sigs.k8s.io/cluster-api@v1.7.1/docs/book/src/developer/providers/migrations/v0.3-to-v0.4.md (about)

     1  # Cluster API v0.3 compared to v0.4
     2  
     3  ## Minimum Go version
     4  
     5  - The Go version used by Cluster API is now Go 1.16+
     6    - In case cloudbuild is used to push images, please upgrade to `gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20211013-1be7868d8b`
     7      in the cloudbuild YAML files.
     8  
     9  ## Controller Runtime version
    10  
    11  - The Controller Runtime version is now v0.9.+
    12  
    13  ## Controller Tools version (if used)
    14  
    15  - The Controller Tools version is now v0.6.+
    16  
    17  ## Kind version
    18  
    19  - The KIND version used for this release is v0.11.x
    20  
    21  ## ⚠ Go Module changes ⚠
    22  
    23  - The `test` folder now ships with its own Go module `sigs.k8s.io/cluster-api/test`.
    24  - The module is going to be tagged and versioned as part of the release.
    25  - Folks importing the test e2e framework or the Docker infrastructure provider need to import the new module.
    26    - When imported, the test module version should always match the Cluster API one.
    27    - Add the following line in `go.mod` to replace the cluster-api dependency in the test module (change the version to your current Cluster API version):
    28    ```
    29    replace sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v0.4.x
    30    ```
    31  - The CAPD go module in test/infrastructure/docker has been removed.
    32  
    33  ## Klog version
    34  
    35  - The klog package used has been upgraded to v2.5.x. It is recommended that
    36    all providers also switch to using v2.
    37  
    38    - Change `import k8s.io/klog` to `import k8s.io/klog/v2`
    39    - Change `import k8s.io/klog/klogr` to `import k8s.io/klog/v2/klogr`
    40    - Update `go.mod` to `k8s.io/klog/v2 v2.5.0`
    41    - Run `go mod tidy` to ensure all dependencies are updated.
    42  
    43  ## The controllers.DeleteNodeAnnotation constant has been removed
    44  
    45  - This annotation `cluster.k8s.io/delete-machine` was originally deprecated a while ago when we moved our types under the `x-k8s.io` domain.
    46  
    47  ## The controllers.DeleteMachineAnnotation has been moved to v1alpha4.DeleteMachineAnnotation
    48  
    49  - This annotation was previously exported as part of the controllers package, instead this should be a versioned annotation under the api packages.
    50  
    51  ## Align manager flag names with upstream Kubernetes components
    52  
    53  - Rename `--metrics-addr` to `--metrics-bind-addr`
    54  - Rename `--leader-election` to `--leader-elect`
    55  
    56  ## util.ManagerDelegatingClientFunc has been removed
    57  
    58  This function was originally used to generate a delegating client when creating a new manager.
    59  
    60  Controller Runtime v0.9.x now uses a `ClientBuilder` in its Options struct and it uses
    61  the delegating client by default under the hood, so this can be now removed.
    62  
    63  ## Use to Controller Runtime's new fake client builder
    64  
    65  - The functions `fake.NewFakeClientWithScheme` and `fake.NewFakeClient` have been deprecated.
    66  - Switch to `fake.NewClientBuilder().WithObjects().Build()` instead, which provides a cleaner interface
    67    to create a new fake client with objects, lists, or a scheme.
    68  
    69  ## Multi tenancy
    70  
    71  Up until v1alpha3, the need of supporting multiple credentials was addressed by running multiple
    72  instances of the same provider, each one with its own set of credentials while watching different namespaces.
    73  
    74  Starting from v1alpha4 instead we are going require that an infrastructure provider should manage different credentials,
    75  each one of them corresponding to an infrastructure tenant.
    76  
    77  see [Multi-tenancy](../../architecture/controllers/multi-tenancy.md) and [Support multiple instances](../../architecture/controllers/support-multiple-instances.md) for
    78  more details.
    79  
    80  Specific changes related to this topic will be detailed in this document.
    81  
    82  ## Change types with arrays of pointers to custom objects
    83  
    84  The conversion-gen code from the `1.20.x` release onward generates incorrect conversion functions for types having arrays of pointers to custom objects. Change the existing types to contain objects instead of pointer references.
    85  
    86  ## Optional flag for specifying webhook certificates dir
    87  Add optional flag `--webhook-cert-dir={string-value}` which allows user to specify directory where webhooks will get tls certificates.
    88  If flag has not provided, default value from `controller-runtime` should be used.
    89  
    90  ## Required kustomize changes to have a single manager watching all namespaces and answer to webhook calls
    91  
    92  In an effort to simplify the management of Cluster API components, and realign with Kubebuilder configuration,
    93  we're requiring some changes to move all webhooks back into a single deployment manager, and to allow Cluster
    94  API watch all namespaces it manages.
    95  For a `/config` folder reference, please use the testdata in the Kubebuilder project: https://github.com/kubernetes-sigs/kubebuilder/tree/master/testdata/project-v3/config
    96  
    97  **Pre-requisites**
    98  
    99  Provider's `/config` folder has the same structure of  `/config` folder in CAPI controllers.
   100  
   101  **Changes in the `/config/webhook` folder:**
   102  
   103  1. Edit the `/config/webhook/kustomization.yaml` file:
   104      - Remove the `namespace:` configuration
   105      - In the `resources:` list, remove the following items:
   106        ```
   107        - ../certmanager
   108        - ../manager
   109        ```
   110      - Remove the `patchesStrategicMerge` list
   111      - Copy the `vars` list into a temporary file to be used later in the process
   112      - Remove the `vars` list
   113  1. Edit the `config/webhook/kustomizeconfig.yaml` file:
   114      - In the `varReference:` list, remove the item with `kind: Deployment`
   115  1. Edit the `/config/webhook/manager_webhook_patch.yaml` file and remove
   116     the `args` list from the `manager` container.
   117  1. Move the following files to the `/config/default` folder
   118      - `/config/webhook/manager_webhook_patch.yaml`
   119      - `/config/webhook/webhookcainjection_patch.yaml`
   120  
   121  **Changes in the `/config/manager` folder:**
   122  
   123  1. Edit the `/config/manager/kustomization.yaml` file:
   124      - Remove the `patchesStrategicMerge` list
   125  1. Edit the `/config/manager/manager.yaml` file:
   126      - Add the following items to the `args` list for the `manager` container list
   127      ```
   128      - "--metrics-bind-addr=127.0.0.1:8080"
   129      ```
   130      - Verify that feature flags required by your container are properly set
   131        (as it was in `/config/webhook/manager_webhook_patch.yaml`).
   132  1. Edit the `/config/manager/manager_auth_proxy_patch.yaml` file:
   133      - Remove the patch for the container with name `manager`
   134  1. Move the following files to the `/config/default` folder
   135      - `/config/manager/manager_auth_proxy_patch.yaml`
   136      - `/config/manager/manager_image_patch.yaml`
   137      - `/config/manager/manager_pull_policy.yaml`
   138  
   139  **Changes in the `/config/default` folder:**
   140  1. Create a file named `/config/default/kustomizeconfig.yaml` with the following content:
   141     ```
   142     # This configuration is for teaching kustomize how to update name ref and var substitution
   143     varReference:
   144     - kind: Deployment
   145       path: spec/template/spec/volumes/secret/secretName
   146     ```
   147  1. Edit the `/config/default/kustomization.yaml` file:
   148      - Add the `namePrefix` and the `commonLabels` configuration values copying values from the `/config/kustomization.yaml` file
   149      - In the `bases:` list, add the following items:
   150        ```
   151        - ../crd
   152        - ../certmanager
   153        - ../webhook
   154        ```
   155      - Add the `patchesStrategicMerge:` list, with the following items:
   156        ```
   157        - manager_auth_proxy_patch.yaml
   158        - manager_image_patch.yaml
   159        - manager_pull_policy.yaml
   160        - manager_webhook_patch.yaml
   161        - webhookcainjection_patch.yaml
   162        ```
   163      - Add a `vars:` configuration using the value from the temporary file created while modifying `/config/webhook/kustomization.yaml`
   164      - Add the `configurations:` list with the following items:
   165        ```
   166        - kustomizeconfig.yaml
   167        ```
   168  
   169  **Changes in the `/config` folder:**
   170  
   171  1. Remove the `/config/kustomization.yaml` file
   172  1. Remove the `/config/patch_crd_webhook_namespace.yaml` file
   173  
   174  **Changes in the `main.go` file:**
   175  
   176  1. Change default value for the flags `webhook-port` flag to `9443`
   177  1. Change your code so all the controllers and the webhooks are started no matter if the webhooks port selected.
   178  
   179  **Other changes:**
   180  
   181  - makefile
   182      - update all the references for `/config/manager/manager_image_patch.yaml` to `/config/default/manager_image_patch.yaml`
   183      - update all the references for `/config/manager/manager_pull_policy.yaml` to `/config/default/manager_pull_policy.yaml`
   184      - update all the call to `kustomize` targeting `/config` to target `/config/default` instead.
   185  - E2E config files
   186      - update provider sources reading from `/config` to read from `/config/default` instead.
   187  - clusterctl-settings.json file
   188      - if the `configFolder` value is defined, update from `/config` to `/config/default`.
   189  
   190  ## Upgrade cert-manager to v1.1.0
   191  
   192  NB. instructions assumes "Required kustomize changes to have a single manager watching all namespaces and answer to webhook calls"
   193  should be executed before this changes.
   194  
   195  **Changes in the `/config/certmanager` folder:**
   196  
   197  1. Edit the `/config/certmanager/certificate.yaml` file and replace all the occurrences of `cert-manager.io/v1alpha2`
   198     with `cert-manager.io/v1`
   199  
   200  **Changes in the `/config/default` folder:**
   201  
   202  1. Edit the `/config/default/kustomization.yaml` file and replace all the occurrences of
   203     ```
   204           kind: Certificate
   205           group: cert-manager.io
   206           version: v1alpha2
   207     ```
   208     with
   209     ```
   210           kind: Certificate
   211           group: cert-manager.io
   212           version: v1
   213     ```
   214  ## Support the cluster.x-k8s.io/watch-filter label and watch-filter flag.
   215  
   216  - A new label `cluster.x-k8s.io/watch-filter` provides the ability to filter the controllers to only reconcile objects with a specific label.
   217  - A new flag `watch-filter` enables users to specify the label value for the `cluster.x-k8s.io/watch-filter` label on controller boot.
   218  - The flag which enables users to set the flag value can be structured like this:
   219    ```go
   220    	fs.StringVar(&watchFilterValue, "watch-filter", "", fmt.Sprintf("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects.", clusterv1.WatchLabel))
   221    ```
   222  - The `ResourceNotPausedAndHasFilterLabel` predicate is a useful helper to check for the pause annotation and the filter label easily:
   223    ```go
   224    c, err := ctrl.NewControllerManagedBy(mgr).
   225  		For(&clusterv1.MachineSet{}).
   226  		Owns(&clusterv1.Machine{}).
   227  		Watches(
   228  			&source.Kind{Type: &clusterv1.Machine{}},
   229  			handler.EnqueueRequestsFromMapFunc(r.MachineToMachineSets),
   230  		).
   231  		WithOptions(options).
   232  		WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
   233  		Build(r)
   234  	if err != nil {
   235  		return errors.Wrap(err, "failed setting up with a controller manager")
   236  	}
   237    ```
   238  
   239  ## Required changes to have individual service accounts for controllers.
   240  
   241  1. Create a new service account such as:
   242    ```yaml
   243    apiVersion: v1
   244    kind: ServiceAccount
   245    metadata:
   246      name: manager
   247    namespace: system
   248    ```
   249  2. Change the `subject` of the managers `ClusterRoleBinding` to match:
   250    ```yaml
   251    subjects:
   252    - kind: ServiceAccount
   253      name: manager
   254      namespace: system
   255    ```
   256  3. Add the correct `serviceAccountName` to the manager deployment:
   257    ```yaml
   258    serviceAccountName: manager
   259    ```
   260  
   261  ## Percentage String or Int API input will fail with a string different from an integer with % appended.
   262  
   263  `MachineDeployment.Spec.Strategy.RollingUpdate.MaxSurge`, `MachineDeployment.Spec.Strategy.RollingUpdate.MaxUnavailable` and `MachineHealthCheck.Spec.MaxUnhealthy` would have previously taken a String value with an integer character in it e.g "3" as a valid input and process it as a percentage value.
   264  Only String values like "3%" or Int values e.g 3 are valid input values now. A string not matching the percentage format will fail, e.g "3".
   265  
   266  ## Required change to support externally managed infrastructure.
   267  
   268  - A new annotation `cluster.x-k8s.io/managed-by` has been introduced that allows cluster infrastructure to be managed
   269    externally.
   270  - When this annotation is added to an `InfraCluster` resource, the controller for these resources should not reconcile
   271    the resource.
   272  - The `ResourceIsNotExternallyManaged` predicate is a useful helper to check for the annotation and the filter the resource easily:
   273    ```go
   274    c, err := ctrl.NewControllerManagedBy(mgr).
   275  		For(&providerv1.InfraCluster{}).
   276  		Watches(...).
   277  		WithOptions(options).
   278  		WithEventFilter(predicates.ResourceIsNotExternallyManaged(ctrl.LoggerFrom(ctx))).
   279  		Build(r)
   280  	if err != nil {
   281  		return errors.Wrap(err, "failed setting up with a controller manager")
   282  	}
   283    ```
   284  - Note: this annotation also has to be checked in other cases, e.g. when watching for the Cluster resource.
   285  
   286  ## MachinePool API group changed to `cluster.x-k8s.io`
   287  
   288  MachinePool is today an experiment, and the API group we originally decided to pick was `exp.cluster.x-k8s.io`. Given that the intent is in the future to move MachinePool to the core API group, we changed the experiment to use `cluster.x-k8s.io` group to avoid future breaking changes.
   289  
   290  All InfraMachinePool implementations should be moved to `infrastructure.cluster.x-k8s.io`. See `DockerMachinePool` for an example.
   291  
   292  Note that MachinePools are still experimental after this change and should still be feature gated.
   293  
   294  ## Golangci-lint configuration
   295  
   296  There were a lot of new useful linters added to `.golangci.yml`. Of course it's not mandatory to use `golangci-lint` or
   297  a similar configuration, but it might make sense regardless. Please note there was previously an error in
   298  the `exclude` configuration which has been fixed in [#4657](https://github.com/kubernetes-sigs/cluster-api/pull/4657). As
   299  this configuration has been duplicated in a few other providers, it could be that you're also affected.
   300  
   301  # test/helpers.NewFakeClientWithScheme has been removed
   302  
   303  This function used to create a new fake client with the given scheme for testing,
   304  and all the objects given as input were initialized with a resource version of "1".
   305  The behavior of having a resource version in fake client has been fixed in controller-runtime,
   306  and this function isn't needed anymore.
   307  
   308  ## Required kustomize changes to remove kube-rbac-proxy
   309  
   310  NB. instructions assumes "Required kustomize changes to have a single manager watching all namespaces and answer to webhook calls"
   311  should be executed before this changes.
   312  
   313  **Changes in the `/config/default` folder:**
   314  1. Edit `/config/default/kustomization.yaml` and remove the `manager_auth_proxy_patch.yaml` item from the `patchesStrategicMerge` list.
   315  1. Delete the `/config/default/manager_auth_proxy_patch.yaml` file.
   316  
   317  **Changes in the `/config/manager` folder:**
   318  1. Edit `/config/manager/manager.yaml` and remove the `--metrics-bind-addr=127.0.0.1:8080` arg from the `args` list.
   319  
   320  **Changes in the `/config/rbac` folder:**
   321  1. Edit `/config/rbac/kustomization.yaml` and remove following items from the `resources` list.
   322     - `auth_proxy_service.yaml`
   323     - `auth_proxy_role.yaml`
   324     - `auth_proxy_role_binding.yaml`
   325  1. Delete the `/config/rbac/auth_proxy_service.yaml` file.
   326  1. Delete the `/config/rbac/auth_proxy_role.yaml` file.
   327  1. Delete the `/config/rbac/auth_proxy_role_binding.yaml` file.
   328  
   329  **Changes in the `main.go` file:**
   330  1. Change the default value for the `metrics-bind-addr` from `:8080` to `localhost:8080`
   331  
   332  ## Required cluster template changes
   333  
   334  - `spec.infrastructureTemplate` has been moved to `spec.machineTemplate.infrastructureRef`. Thus, cluster templates which include `KubeadmControlPlane`
   335  have to be adjusted accordingly.
   336  - `spec.nodeDrainTimeout` has been moved to `spec.machineTemplate.nodeDrainTimeout`.
   337  
   338  ## Required spec and status fields for Control Planes using 'version' for ClusterClass support
   339  ControlPlane implementations using version must now [include a 'version' field as defined below in both its spec and its status](../../architecture/controllers/control-plane.md#required-spec-fields-for-implementations-using-version).
   340  
   341   `spec.version` - is a string representing the Kubernetes version to be used
   342    by the control plane machines. The value must be a valid semantic version;
   343    also if the value provided by the user does not start with the v prefix, it
   344    must be added.
   345  
   346  `status.version` - is a string representing the minimum Kubernetes version for the control plane machines in the cluster.
   347  
   348  Please note that implementing these fields are a requirement for a control plane provider to be used with ClusterClass and managed topologies.
   349  
   350  ## Required spec fields for Control Planes using 'Machines' for ClusterClass support
   351  ControlPlane implementations that use an underlying MachineInfrastructure must now [include a 'machineTemplate' as defined below, with subordinate fields, in its Spec.](../../architecture/controllers/control-plane.md#required-spec-fields-for-implementations-using-machines)
   352  
   353  
   354   `machineTemplate` - is a struct containing details of the control plane
   355    machine template.
   356  
   357   Please note that implementing this field for control plane providers using machines is a requirement for ClusterClass and managed topologies to work consistently across all providers.
   358