diff --git a/api/v1alpha2/addonprovider_wrapper.go b/api/v1alpha2/addonprovider_wrapper.go new file mode 100644 index 000000000..f1f6d5e25 --- /dev/null +++ b/api/v1alpha2/addonprovider_wrapper.go @@ -0,0 +1,61 @@ +/* +Copyright 2023 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha2 + +import ( + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" +) + +var _ GenericProvider = &AddonProvider{} + +func (b *AddonProvider) GetConditions() clusterv1.Conditions { + return b.Status.Conditions +} + +func (b *AddonProvider) SetConditions(conditions clusterv1.Conditions) { + b.Status.Conditions = conditions +} + +func (b *AddonProvider) GetSpec() ProviderSpec { + return b.Spec.ProviderSpec +} + +func (b *AddonProvider) SetSpec(in ProviderSpec) { + b.Spec.ProviderSpec = in +} + +func (b *AddonProvider) GetStatus() ProviderStatus { + return b.Status.ProviderStatus +} + +func (b *AddonProvider) SetStatus(in ProviderStatus) { + b.Status.ProviderStatus = in +} + +func (b *AddonProvider) GetType() string { + return "addon" +} + +func (b *AddonProviderList) GetItems() []GenericProvider { + providers := []GenericProvider{} + + for index := range b.Items { + providers = append(providers, &b.Items[index]) + } + + return providers +} diff --git a/api/v1alpha2/bootstrapprovider_wrapper.go b/api/v1alpha2/bootstrapprovider_wrapper.go new file mode 100644 index 000000000..db5b575ba --- /dev/null +++ b/api/v1alpha2/bootstrapprovider_wrapper.go @@ -0,0 +1,61 @@ +/* +Copyright 2021 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha2 + +import ( + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" +) + +var _ GenericProvider = &BootstrapProvider{} + +func (b *BootstrapProvider) GetConditions() clusterv1.Conditions { + return b.Status.Conditions +} + +func (b *BootstrapProvider) SetConditions(conditions clusterv1.Conditions) { + b.Status.Conditions = conditions +} + +func (b *BootstrapProvider) GetSpec() ProviderSpec { + return b.Spec.ProviderSpec +} + +func (b *BootstrapProvider) SetSpec(in ProviderSpec) { + b.Spec.ProviderSpec = in +} + +func (b *BootstrapProvider) GetStatus() ProviderStatus { + return b.Status.ProviderStatus +} + +func (b *BootstrapProvider) SetStatus(in ProviderStatus) { + b.Status.ProviderStatus = in +} + +func (b *BootstrapProvider) GetType() string { + return "bootstrap" +} + +func (b *BootstrapProviderList) GetItems() []GenericProvider { + providers := []GenericProvider{} + + for index := range b.Items { + providers = append(providers, &b.Items[index]) + } + + return providers +} diff --git a/api/v1alpha2/controlplaneprovider_wrapper.go b/api/v1alpha2/controlplaneprovider_wrapper.go new file mode 100644 index 000000000..a8f1009cd --- /dev/null +++ b/api/v1alpha2/controlplaneprovider_wrapper.go @@ -0,0 +1,61 @@ +/* +Copyright 2021 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha2 + +import ( + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" +) + +var _ GenericProvider = &ControlPlaneProvider{} + +func (c *ControlPlaneProvider) GetConditions() clusterv1.Conditions { + return c.Status.Conditions +} + +func (c *ControlPlaneProvider) SetConditions(conditions clusterv1.Conditions) { + c.Status.Conditions = conditions +} + +func (c *ControlPlaneProvider) GetSpec() ProviderSpec { + return c.Spec.ProviderSpec +} + +func (c *ControlPlaneProvider) SetSpec(in ProviderSpec) { + c.Spec.ProviderSpec = in +} + +func (c *ControlPlaneProvider) GetStatus() ProviderStatus { + return c.Status.ProviderStatus +} + +func (c *ControlPlaneProvider) SetStatus(in ProviderStatus) { + c.Status.ProviderStatus = in +} + +func (c *ControlPlaneProvider) GetType() string { + return "controlplane" +} + +func (c *ControlPlaneProviderList) GetItems() []GenericProvider { + providers := make([]GenericProvider, len(c.Items)) + + for index := range c.Items { + providers[index] = &c.Items[index] + } + + return providers +} diff --git a/api/v1alpha2/coreprovider_wrapper.go b/api/v1alpha2/coreprovider_wrapper.go new file mode 100644 index 000000000..f8c34481c --- /dev/null +++ b/api/v1alpha2/coreprovider_wrapper.go @@ -0,0 +1,61 @@ +/* +Copyright 2021 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha2 + +import ( + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" +) + +var _ GenericProvider = &CoreProvider{} + +func (c *CoreProvider) GetConditions() clusterv1.Conditions { + return c.Status.Conditions +} + +func (c *CoreProvider) SetConditions(conditions clusterv1.Conditions) { + c.Status.Conditions = conditions +} + +func (c *CoreProvider) GetSpec() ProviderSpec { + return c.Spec.ProviderSpec +} + +func (c *CoreProvider) SetSpec(in ProviderSpec) { + c.Spec.ProviderSpec = in +} + +func (c *CoreProvider) GetStatus() ProviderStatus { + return c.Status.ProviderStatus +} + +func (c *CoreProvider) SetStatus(in ProviderStatus) { + c.Status.ProviderStatus = in +} + +func (c *CoreProvider) GetType() string { + return "core" +} + +func (c *CoreProviderList) GetItems() []GenericProvider { + providers := make([]GenericProvider, len(c.Items)) + + for index := range c.Items { + providers[index] = &c.Items[index] + } + + return providers +} diff --git a/api/v1alpha2/genericprovider_interfaces.go b/api/v1alpha2/genericprovider_interfaces.go new file mode 100644 index 000000000..90c713956 --- /dev/null +++ b/api/v1alpha2/genericprovider_interfaces.go @@ -0,0 +1,40 @@ +/* +Copyright 2021 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha2 + +import ( + "sigs.k8s.io/cluster-api/util/conditions" +) + +// GenericProvider interface describes operations applicable to the provider type. +// +// +kubebuilder:object:generate=false +type GenericProvider interface { + conditions.Setter + GetSpec() ProviderSpec + SetSpec(in ProviderSpec) + GetStatus() ProviderStatus + SetStatus(in ProviderStatus) + GetType() string +} + +// GenericProviderList interface describes operations applicable to the provider list type. +// +// +kubebuilder:object:generate=false +type GenericProviderList interface { + GetItems() []GenericProvider +} diff --git a/api/v1alpha2/infrastructureprovider_wrapper.go b/api/v1alpha2/infrastructureprovider_wrapper.go new file mode 100644 index 000000000..1be23275b --- /dev/null +++ b/api/v1alpha2/infrastructureprovider_wrapper.go @@ -0,0 +1,61 @@ +/* +Copyright 2021 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha2 + +import ( + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" +) + +var _ GenericProvider = &InfrastructureProvider{} + +func (c *InfrastructureProvider) GetConditions() clusterv1.Conditions { + return c.Status.Conditions +} + +func (c *InfrastructureProvider) SetConditions(conditions clusterv1.Conditions) { + c.Status.Conditions = conditions +} + +func (c *InfrastructureProvider) GetSpec() ProviderSpec { + return c.Spec.ProviderSpec +} + +func (c *InfrastructureProvider) SetSpec(in ProviderSpec) { + c.Spec.ProviderSpec = in +} + +func (c *InfrastructureProvider) GetStatus() ProviderStatus { + return c.Status.ProviderStatus +} + +func (c *InfrastructureProvider) SetStatus(in ProviderStatus) { + c.Status.ProviderStatus = in +} + +func (c *InfrastructureProvider) GetType() string { + return "infrastructure" +} + +func (c *InfrastructureProviderList) GetItems() []GenericProvider { + providers := make([]GenericProvider, len(c.Items)) + + for index := range c.Items { + providers[index] = &c.Items[index] + } + + return providers +} diff --git a/api/v1alpha2/provider_types.go b/api/v1alpha2/provider_types.go index d2bd04711..9cfdcc310 100644 --- a/api/v1alpha2/provider_types.go +++ b/api/v1alpha2/provider_types.go @@ -148,7 +148,7 @@ type DeploymentSpec struct { // List of containers specified in the Deployment // +optional - Containers []ContainerSpec `json:"containers"` + Containers []ContainerSpec `json:"containers,omitempty"` // If specified, the pod's service account // +optional diff --git a/cmd/plugin/cmd/upgrade_plan.go b/cmd/plugin/cmd/upgrade_plan.go index 731e03675..565698eef 100644 --- a/cmd/plugin/cmd/upgrade_plan.go +++ b/cmd/plugin/cmd/upgrade_plan.go @@ -26,7 +26,7 @@ import ( "github.com/spf13/cobra" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api-operator/internal/controller/genericprovider" + operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" ) type upgradePlanOptions struct { @@ -50,7 +50,7 @@ type upgradePlan struct { // upgradeItem defines a possible upgrade target for a provider in the management cluster. type upgradeItem struct { - genericprovider.GenericProvider + operatorv1.GenericProvider NextVersion string } diff --git a/controllers/alias.go b/controllers/alias.go deleted file mode 100644 index c1cb4ba90..000000000 --- a/controllers/alias.go +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright 2023 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controllers - -import ( - "k8s.io/client-go/rest" - providercontroller "sigs.k8s.io/cluster-api-operator/internal/controller" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" -) - -type GenericProviderReconciler struct { - Provider client.Object - ProviderList client.ObjectList - Client client.Client - Config *rest.Config -} - -func (r *GenericProviderReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error { - return (&providercontroller.GenericProviderReconciler{ - Provider: r.Provider, - ProviderList: r.ProviderList, - Client: r.Client, - Config: r.Config, - }).SetupWithManager(mgr, options) -} diff --git a/internal/controller/component_customizer.go b/internal/controller/component_customizer.go index 30be7d6fc..e34720dc0 100644 --- a/internal/controller/component_customizer.go +++ b/internal/controller/component_customizer.go @@ -30,7 +30,6 @@ import ( configv1alpha1 "k8s.io/component-base/config/v1alpha1" "k8s.io/utils/pointer" operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" - "sigs.k8s.io/cluster-api-operator/internal/controller/genericprovider" "sigs.k8s.io/cluster-api/util" ) @@ -44,7 +43,7 @@ const ( var bool2Str = map[bool]string{true: "true", false: "false"} // customizeObjectsFn apply provider specific customization to a list of manifests. -func customizeObjectsFn(provider genericprovider.GenericProvider) func(objs []unstructured.Unstructured) ([]unstructured.Unstructured, error) { +func customizeObjectsFn(provider operatorv1.GenericProvider) func(objs []unstructured.Unstructured) ([]unstructured.Unstructured, error) { return func(objs []unstructured.Unstructured) ([]unstructured.Unstructured, error) { results := []unstructured.Unstructured{} diff --git a/internal/controller/component_patches.go b/internal/controller/component_patches.go index a2dd9982c..f1b4648d0 100644 --- a/internal/controller/component_patches.go +++ b/internal/controller/component_patches.go @@ -20,12 +20,13 @@ import ( "context" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "sigs.k8s.io/cluster-api-operator/internal/controller/genericprovider" + + operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" "sigs.k8s.io/cluster-api-operator/internal/patch" ctrl "sigs.k8s.io/controller-runtime" ) -func applyPatches(ctx context.Context, provider genericprovider.GenericProvider) func(objs []unstructured.Unstructured) ([]unstructured.Unstructured, error) { +func applyPatches(ctx context.Context, provider operatorv1.GenericProvider) func(objs []unstructured.Unstructured) ([]unstructured.Unstructured, error) { log := ctrl.LoggerFrom(ctx) return func(objs []unstructured.Unstructured) ([]unstructured.Unstructured, error) { diff --git a/internal/controller/genericprovider/addonprovider_wrapper.go b/internal/controller/genericprovider/addonprovider_wrapper.go deleted file mode 100644 index f99b155c1..000000000 --- a/internal/controller/genericprovider/addonprovider_wrapper.go +++ /dev/null @@ -1,77 +0,0 @@ -/* -Copyright 2023 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package genericprovider - -import ( - operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -type AddonProviderWrapper struct { - *operatorv1.AddonProvider -} - -func (b *AddonProviderWrapper) GetConditions() clusterv1.Conditions { - return b.Status.Conditions -} - -func (b *AddonProviderWrapper) SetConditions(conditions clusterv1.Conditions) { - b.Status.Conditions = conditions -} - -func (b *AddonProviderWrapper) GetSpec() operatorv1.ProviderSpec { - return b.Spec.ProviderSpec -} - -func (b *AddonProviderWrapper) SetSpec(in operatorv1.ProviderSpec) { - b.Spec.ProviderSpec = in -} - -func (b *AddonProviderWrapper) GetStatus() operatorv1.ProviderStatus { - return b.Status.ProviderStatus -} - -func (b *AddonProviderWrapper) SetStatus(in operatorv1.ProviderStatus) { - b.Status.ProviderStatus = in -} - -func (b *AddonProviderWrapper) GetObject() client.Object { - return b.AddonProvider -} - -func (b *AddonProviderWrapper) GetType() string { - return "addon" -} - -type AddonProviderListWrapper struct { - *operatorv1.AddonProviderList -} - -func (b *AddonProviderListWrapper) GetItems() []GenericProvider { - providers := []GenericProvider{} - - for index := range b.Items { - providers = append(providers, &AddonProviderWrapper{&b.Items[index]}) - } - - return providers -} - -func (b *AddonProviderListWrapper) GetObject() client.ObjectList { - return b.AddonProviderList -} diff --git a/internal/controller/genericprovider/bootstrapprovider_wrapper.go b/internal/controller/genericprovider/bootstrapprovider_wrapper.go deleted file mode 100644 index be47c4f9d..000000000 --- a/internal/controller/genericprovider/bootstrapprovider_wrapper.go +++ /dev/null @@ -1,77 +0,0 @@ -/* -Copyright 2021 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package genericprovider - -import ( - operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -type BootstrapProviderWrapper struct { - *operatorv1.BootstrapProvider -} - -func (b *BootstrapProviderWrapper) GetConditions() clusterv1.Conditions { - return b.Status.Conditions -} - -func (b *BootstrapProviderWrapper) SetConditions(conditions clusterv1.Conditions) { - b.Status.Conditions = conditions -} - -func (b *BootstrapProviderWrapper) GetSpec() operatorv1.ProviderSpec { - return b.Spec.ProviderSpec -} - -func (b *BootstrapProviderWrapper) SetSpec(in operatorv1.ProviderSpec) { - b.Spec.ProviderSpec = in -} - -func (b *BootstrapProviderWrapper) GetStatus() operatorv1.ProviderStatus { - return b.Status.ProviderStatus -} - -func (b *BootstrapProviderWrapper) SetStatus(in operatorv1.ProviderStatus) { - b.Status.ProviderStatus = in -} - -func (b *BootstrapProviderWrapper) GetObject() client.Object { - return b.BootstrapProvider -} - -func (b *BootstrapProviderWrapper) GetType() string { - return "bootstrap" -} - -type BootstrapProviderListWrapper struct { - *operatorv1.BootstrapProviderList -} - -func (b *BootstrapProviderListWrapper) GetItems() []GenericProvider { - providers := []GenericProvider{} - - for index := range b.Items { - providers = append(providers, &BootstrapProviderWrapper{&b.Items[index]}) - } - - return providers -} - -func (b *BootstrapProviderListWrapper) GetObject() client.ObjectList { - return b.BootstrapProviderList -} diff --git a/internal/controller/genericprovider/controlplaneprovider_wrapper.go b/internal/controller/genericprovider/controlplaneprovider_wrapper.go deleted file mode 100644 index 1a30ea333..000000000 --- a/internal/controller/genericprovider/controlplaneprovider_wrapper.go +++ /dev/null @@ -1,77 +0,0 @@ -/* -Copyright 2021 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package genericprovider - -import ( - operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -type ControlPlaneProviderWrapper struct { - *operatorv1.ControlPlaneProvider -} - -func (c *ControlPlaneProviderWrapper) GetConditions() clusterv1.Conditions { - return c.Status.Conditions -} - -func (c *ControlPlaneProviderWrapper) SetConditions(conditions clusterv1.Conditions) { - c.Status.Conditions = conditions -} - -func (c *ControlPlaneProviderWrapper) GetSpec() operatorv1.ProviderSpec { - return c.Spec.ProviderSpec -} - -func (c *ControlPlaneProviderWrapper) SetSpec(in operatorv1.ProviderSpec) { - c.Spec.ProviderSpec = in -} - -func (c *ControlPlaneProviderWrapper) GetStatus() operatorv1.ProviderStatus { - return c.Status.ProviderStatus -} - -func (c *ControlPlaneProviderWrapper) SetStatus(in operatorv1.ProviderStatus) { - c.Status.ProviderStatus = in -} - -func (c *ControlPlaneProviderWrapper) GetObject() client.Object { - return c.ControlPlaneProvider -} - -func (c *ControlPlaneProviderWrapper) GetType() string { - return "controlplane" -} - -type ControlPlaneProviderListWrapper struct { - *operatorv1.ControlPlaneProviderList -} - -func (c *ControlPlaneProviderListWrapper) GetItems() []GenericProvider { - providers := []GenericProvider{} - - for index := range c.Items { - providers = append(providers, &ControlPlaneProviderWrapper{&c.Items[index]}) - } - - return providers -} - -func (c *ControlPlaneProviderListWrapper) GetObject() client.ObjectList { - return c.ControlPlaneProviderList -} diff --git a/internal/controller/genericprovider/coreprovider_wrapper.go b/internal/controller/genericprovider/coreprovider_wrapper.go deleted file mode 100644 index 22b68e1dc..000000000 --- a/internal/controller/genericprovider/coreprovider_wrapper.go +++ /dev/null @@ -1,77 +0,0 @@ -/* -Copyright 2021 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package genericprovider - -import ( - operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -type CoreProviderWrapper struct { - *operatorv1.CoreProvider -} - -func (c *CoreProviderWrapper) GetConditions() clusterv1.Conditions { - return c.Status.Conditions -} - -func (c *CoreProviderWrapper) SetConditions(conditions clusterv1.Conditions) { - c.Status.Conditions = conditions -} - -func (c *CoreProviderWrapper) GetSpec() operatorv1.ProviderSpec { - return c.Spec.ProviderSpec -} - -func (c *CoreProviderWrapper) SetSpec(in operatorv1.ProviderSpec) { - c.Spec.ProviderSpec = in -} - -func (c *CoreProviderWrapper) GetStatus() operatorv1.ProviderStatus { - return c.Status.ProviderStatus -} - -func (c *CoreProviderWrapper) SetStatus(in operatorv1.ProviderStatus) { - c.Status.ProviderStatus = in -} - -func (c *CoreProviderWrapper) GetObject() client.Object { - return c.CoreProvider -} - -func (c *CoreProviderWrapper) GetType() string { - return "core" -} - -type CoreProviderListWrapper struct { - *operatorv1.CoreProviderList -} - -func (c *CoreProviderListWrapper) GetItems() []GenericProvider { - providers := []GenericProvider{} - - for index := range c.Items { - providers = append(providers, &CoreProviderWrapper{&c.Items[index]}) - } - - return providers -} - -func (c *CoreProviderListWrapper) GetObject() client.ObjectList { - return c.CoreProviderList -} diff --git a/internal/controller/genericprovider/genericprovider_interfaces.go b/internal/controller/genericprovider/genericprovider_interfaces.go index 91501e86d..83228fb1f 100644 --- a/internal/controller/genericprovider/genericprovider_interfaces.go +++ b/internal/controller/genericprovider/genericprovider_interfaces.go @@ -18,23 +18,15 @@ package genericprovider import ( operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" - "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/controller-runtime/pkg/client" ) type GenericProvider interface { client.Object - conditions.Setter - GetSpec() operatorv1.ProviderSpec - SetSpec(in operatorv1.ProviderSpec) - GetStatus() operatorv1.ProviderStatus - SetStatus(in operatorv1.ProviderStatus) - GetObject() client.Object - GetType() string + operatorv1.GenericProvider } type GenericProviderList interface { client.ObjectList - GetObject() client.ObjectList - GetItems() []GenericProvider + operatorv1.GenericProviderList } diff --git a/internal/controller/genericprovider/infrastructureprovider_wrapper.go b/internal/controller/genericprovider/infrastructureprovider_wrapper.go deleted file mode 100644 index 8e6aba7d1..000000000 --- a/internal/controller/genericprovider/infrastructureprovider_wrapper.go +++ /dev/null @@ -1,77 +0,0 @@ -/* -Copyright 2021 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package genericprovider - -import ( - operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -type InfrastructureProviderWrapper struct { - *operatorv1.InfrastructureProvider -} - -func (i *InfrastructureProviderWrapper) GetConditions() clusterv1.Conditions { - return i.Status.Conditions -} - -func (i *InfrastructureProviderWrapper) SetConditions(conditions clusterv1.Conditions) { - i.Status.Conditions = conditions -} - -func (i *InfrastructureProviderWrapper) GetSpec() operatorv1.ProviderSpec { - return i.Spec.ProviderSpec -} - -func (i *InfrastructureProviderWrapper) SetSpec(in operatorv1.ProviderSpec) { - i.Spec.ProviderSpec = in -} - -func (i *InfrastructureProviderWrapper) GetStatus() operatorv1.ProviderStatus { - return i.Status.ProviderStatus -} - -func (i *InfrastructureProviderWrapper) SetStatus(in operatorv1.ProviderStatus) { - i.Status.ProviderStatus = in -} - -func (i *InfrastructureProviderWrapper) GetObject() client.Object { - return i.InfrastructureProvider -} - -func (i *InfrastructureProviderWrapper) GetType() string { - return "infrastructure" -} - -type InfrastructureProviderListWrapper struct { - *operatorv1.InfrastructureProviderList -} - -func (i *InfrastructureProviderListWrapper) GetItems() []GenericProvider { - providers := []GenericProvider{} - - for index := range i.Items { - providers = append(providers, &InfrastructureProviderWrapper{&i.Items[index]}) - } - - return providers -} - -func (i *InfrastructureProviderListWrapper) GetObject() client.ObjectList { - return i.InfrastructureProviderList -} diff --git a/internal/controller/genericprovider_controller.go b/internal/controller/genericprovider_controller.go index 197f6a8d3..397161537 100644 --- a/internal/controller/genericprovider_controller.go +++ b/internal/controller/genericprovider_controller.go @@ -22,7 +22,6 @@ import ( "encoding/json" "errors" "fmt" - "reflect" apierrors "k8s.io/apimachinery/pkg/api/errors" kerrors "k8s.io/apimachinery/pkg/util/errors" @@ -40,8 +39,8 @@ import ( ) type GenericProviderReconciler struct { - Provider client.Object - ProviderList client.ObjectList + Provider genericprovider.GenericProvider + ProviderList genericprovider.GenericProviderList Client client.Client Config *rest.Config } @@ -62,17 +61,7 @@ func (r *GenericProviderReconciler) Reconcile(ctx context.Context, req reconcile log.Info("Reconciling provider") - typedProvider, err := r.newGenericProvider() - if err != nil { - return ctrl.Result{}, err - } - - typedProviderList, err := r.newGenericProviderList() - if err != nil { - return ctrl.Result{}, err - } - - if err := r.Client.Get(ctx, req.NamespacedName, typedProvider.GetObject()); err != nil { + if err := r.Client.Get(ctx, req.NamespacedName, r.Provider); err != nil { if apierrors.IsNotFound(err) { // Object not found, return. Created objects are automatically garbage collected. // For additional cleanup logic use finalizers. @@ -83,7 +72,7 @@ func (r *GenericProviderReconciler) Reconcile(ctx context.Context, req reconcile } // Initialize the patch helper - patchHelper, err := patch.NewHelper(typedProvider.GetObject(), r.Client) + patchHelper, err := patch.NewHelper(r.Provider, r.Client) if err != nil { return ctrl.Result{}, err } @@ -96,37 +85,37 @@ func (r *GenericProviderReconciler) Reconcile(ctx context.Context, req reconcile patchOpts = append(patchOpts, patch.WithStatusObservedGeneration{}) } - if err := patchProvider(ctx, typedProvider, patchHelper, patchOpts...); err != nil { + if err := patchProvider(ctx, r.Provider, patchHelper, patchOpts...); err != nil { reterr = kerrors.NewAggregate([]error{reterr, err}) } }() // Add finalizer first if not exist to avoid the race condition between init and delete - if !controllerutil.ContainsFinalizer(typedProvider.GetObject(), operatorv1.ProviderFinalizer) { - controllerutil.AddFinalizer(typedProvider.GetObject(), operatorv1.ProviderFinalizer) + if !controllerutil.ContainsFinalizer(r.Provider, operatorv1.ProviderFinalizer) { + controllerutil.AddFinalizer(r.Provider, operatorv1.ProviderFinalizer) return ctrl.Result{}, nil } // Handle deletion reconciliation loop. - if !typedProvider.GetDeletionTimestamp().IsZero() { - return r.reconcileDelete(ctx, typedProvider) + if !r.Provider.GetDeletionTimestamp().IsZero() { + return r.reconcileDelete(ctx, r.Provider) } // Check if spec hash stays the same and don't go further in this case. - specHash, err := calculateHash(typedProvider.GetSpec()) + specHash, err := calculateHash(r.Provider.GetSpec()) if err != nil { return ctrl.Result{}, err } - if typedProvider.GetAnnotations()[appliedSpecHashAnnotation] == specHash { + if r.Provider.GetAnnotations()[appliedSpecHashAnnotation] == specHash { log.Info("No changes detected, skipping further steps") return ctrl.Result{}, nil } - res, err := r.reconcile(ctx, typedProvider, typedProviderList) + res, err := r.reconcile(ctx, r.Provider, r.ProviderList) - annotations := typedProvider.GetAnnotations() + annotations := r.Provider.GetAnnotations() if annotations == nil { annotations = map[string]string{} } @@ -134,7 +123,7 @@ func (r *GenericProviderReconciler) Reconcile(ctx context.Context, req reconcile // Set the spec hash annotation if reconciliation was successful or reset it otherwise. if res.IsZero() && err == nil { // Recalculate spec hash in case it was changed during reconciliation process. - specHash, err = calculateHash(typedProvider.GetSpec()) + specHash, err = calculateHash(r.Provider.GetSpec()) if err != nil { return ctrl.Result{}, err } @@ -144,12 +133,12 @@ func (r *GenericProviderReconciler) Reconcile(ctx context.Context, req reconcile annotations[appliedSpecHashAnnotation] = "" } - typedProvider.SetAnnotations(annotations) + r.Provider.SetAnnotations(annotations) return res, err } -func patchProvider(ctx context.Context, provider genericprovider.GenericProvider, patchHelper *patch.Helper, options ...patch.Option) error { +func patchProvider(ctx context.Context, provider operatorv1.GenericProvider, patchHelper *patch.Helper, options ...patch.Option) error { conds := []clusterv1.ConditionType{ operatorv1.PreflightCheckCondition, operatorv1.ProviderInstalledCondition, @@ -157,7 +146,7 @@ func patchProvider(ctx context.Context, provider genericprovider.GenericProvider options = append(options, patch.WithOwnedConditions{Conditions: conds}) - return patchHelper.Patch(ctx, provider.GetObject(), options...) + return patchHelper.Patch(ctx, provider, options...) } func (r *GenericProviderReconciler) reconcile(ctx context.Context, provider genericprovider.GenericProvider, genericProviderList genericprovider.GenericProviderList) (ctrl.Result, error) { @@ -194,7 +183,7 @@ func (r *GenericProviderReconciler) reconcile(ctx context.Context, provider gene return res, nil } -func (r *GenericProviderReconciler) reconcileDelete(ctx context.Context, provider genericprovider.GenericProvider) (ctrl.Result, error) { +func (r *GenericProviderReconciler) reconcileDelete(ctx context.Context, provider operatorv1.GenericProvider) (ctrl.Result, error) { log := ctrl.LoggerFrom(ctx) log.Info("Deleting provider resources") @@ -223,51 +212,11 @@ func (r *GenericProviderReconciler) reconcileDelete(ctx context.Context, provide } } - controllerutil.RemoveFinalizer(provider.GetObject(), operatorv1.ProviderFinalizer) + controllerutil.RemoveFinalizer(provider, operatorv1.ProviderFinalizer) return res, nil } -func (r *GenericProviderReconciler) newGenericProvider() (genericprovider.GenericProvider, error) { - switch r.Provider.(type) { - case *operatorv1.CoreProvider: - return &genericprovider.CoreProviderWrapper{CoreProvider: &operatorv1.CoreProvider{}}, nil - case *operatorv1.BootstrapProvider: - return &genericprovider.BootstrapProviderWrapper{BootstrapProvider: &operatorv1.BootstrapProvider{}}, nil - case *operatorv1.ControlPlaneProvider: - return &genericprovider.ControlPlaneProviderWrapper{ControlPlaneProvider: &operatorv1.ControlPlaneProvider{}}, nil - case *operatorv1.InfrastructureProvider: - return &genericprovider.InfrastructureProviderWrapper{InfrastructureProvider: &operatorv1.InfrastructureProvider{}}, nil - case *operatorv1.AddonProvider: - return &genericprovider.AddonProviderWrapper{AddonProvider: &operatorv1.AddonProvider{}}, nil - default: - providerKind := reflect.Indirect(reflect.ValueOf(r.Provider)).Type().Name() - failedToCastInterfaceErr := fmt.Errorf("failed to cast interface for type: %s", providerKind) - - return nil, failedToCastInterfaceErr - } -} - -func (r *GenericProviderReconciler) newGenericProviderList() (genericprovider.GenericProviderList, error) { - switch r.ProviderList.(type) { - case *operatorv1.CoreProviderList: - return &genericprovider.CoreProviderListWrapper{CoreProviderList: &operatorv1.CoreProviderList{}}, nil - case *operatorv1.BootstrapProviderList: - return &genericprovider.BootstrapProviderListWrapper{BootstrapProviderList: &operatorv1.BootstrapProviderList{}}, nil - case *operatorv1.ControlPlaneProviderList: - return &genericprovider.ControlPlaneProviderListWrapper{ControlPlaneProviderList: &operatorv1.ControlPlaneProviderList{}}, nil - case *operatorv1.InfrastructureProviderList: - return &genericprovider.InfrastructureProviderListWrapper{InfrastructureProviderList: &operatorv1.InfrastructureProviderList{}}, nil - case *operatorv1.AddonProviderList: - return &genericprovider.AddonProviderListWrapper{AddonProviderList: &operatorv1.AddonProviderList{}}, nil - default: - providerKind := reflect.Indirect(reflect.ValueOf(r.ProviderList)).Type().Name() - failedToCastInterfaceErr := fmt.Errorf("failed to cast interface for type: %s", providerKind) - - return nil, failedToCastInterfaceErr - } -} - func calculateHash(object interface{}) (string, error) { jsonData, err := json.Marshal(object) if err != nil { diff --git a/internal/controller/genericprovider_controller_test.go b/internal/controller/genericprovider_controller_test.go index 09d07c9d4..abf0680bd 100644 --- a/internal/controller/genericprovider_controller_test.go +++ b/internal/controller/genericprovider_controller_test.go @@ -17,7 +17,6 @@ limitations under the License. package controller import ( - "reflect" "testing" . "github.com/onsi/gomega" @@ -114,15 +113,13 @@ func TestReconcilerPreflightConditions(t *testing.T) { name: "preflight conditions for CoreProvider", namespace: "test-core-provider", providers: []genericprovider.GenericProvider{ - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: testCurrentVersion, - }, + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: testCurrentVersion, }, }, }, @@ -132,37 +129,33 @@ func TestReconcilerPreflightConditions(t *testing.T) { name: "preflight conditions for ControlPlaneProvider", namespace: "test-cp-provider", providers: []genericprovider.GenericProvider{ - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: testCurrentVersion, - }, + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: testCurrentVersion, }, - Status: operatorv1.CoreProviderStatus{ - ProviderStatus: operatorv1.ProviderStatus{ - Conditions: []clusterv1.Condition{ - { - Type: clusterv1.ReadyCondition, - Status: corev1.ConditionTrue, - }, + }, + Status: operatorv1.CoreProviderStatus{ + ProviderStatus: operatorv1.ProviderStatus{ + Conditions: []clusterv1.Condition{ + { + Type: clusterv1.ReadyCondition, + Status: corev1.ConditionTrue, }, }, }, }, }, - &genericprovider.ControlPlaneProviderWrapper{ - ControlPlaneProvider: &operatorv1.ControlPlaneProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "kubeadm", - }, - Spec: operatorv1.ControlPlaneProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: testCurrentVersion, - }, + &operatorv1.ControlPlaneProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "kubeadm", + }, + Spec: operatorv1.ControlPlaneProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: testCurrentVersion, }, }, }, @@ -183,12 +176,12 @@ func TestReconcilerPreflightConditions(t *testing.T) { insertDummyConfig(p) p.SetNamespace(tc.namespace) t.Log("creating test provider", p.GetName()) - g.Expect(env.CreateAndWait(ctx, p.GetObject())).To(Succeed()) + g.Expect(env.CreateAndWait(ctx, p)).To(Succeed()) } g.Eventually(func() bool { for _, p := range tc.providers { - if err := env.Get(ctx, client.ObjectKeyFromObject(p.GetObject()), p.GetObject()); err != nil { + if err := env.Get(ctx, client.ObjectKeyFromObject(p), p); err != nil { return false } @@ -207,7 +200,7 @@ func TestReconcilerPreflightConditions(t *testing.T) { objs := []client.Object{} for _, p := range tc.providers { - objs = append(objs, p.GetObject()) + objs = append(objs, p) } objs = append(objs, &corev1.ConfigMap{ @@ -245,15 +238,13 @@ func TestUpgradeDowngradeProvider(t *testing.T) { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - provider := &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: testCurrentVersion, - }, + provider := &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: testCurrentVersion, }, }, } @@ -268,10 +259,10 @@ func TestUpgradeDowngradeProvider(t *testing.T) { insertDummyConfig(provider) provider.SetNamespace(namespace) t.Log("creating test provider", provider.GetName()) - g.Expect(env.CreateAndWait(ctx, provider.GetObject())).To(Succeed()) + g.Expect(env.CreateAndWait(ctx, provider)).To(Succeed()) g.Eventually(func() bool { - if err := env.Get(ctx, client.ObjectKeyFromObject(provider.GetObject()), provider.GetObject()); err != nil { + if err := env.Get(ctx, client.ObjectKeyFromObject(provider), provider); err != nil { return false } @@ -309,10 +300,10 @@ func TestUpgradeDowngradeProvider(t *testing.T) { labels["provider-version"] = tc.newVersion provider.SetLabels(labels) - g.Expect(env.Client.Update(ctx, provider.GetObject())).To(Succeed()) + g.Expect(env.Client.Update(ctx, provider)).To(Succeed()) g.Eventually(func() bool { - if err := env.Get(ctx, client.ObjectKeyFromObject(provider.GetObject()), provider.GetObject()); err != nil { + if err := env.Get(ctx, client.ObjectKeyFromObject(provider), provider); err != nil { return false } @@ -337,7 +328,7 @@ func TestUpgradeDowngradeProvider(t *testing.T) { }, timeout).Should(BeEquivalentTo(true)) // Clean up - objs := []client.Object{provider.GetObject()} + objs := []client.Object{provider} objs = append(objs, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: testCurrentVersion, @@ -357,112 +348,6 @@ func TestUpgradeDowngradeProvider(t *testing.T) { } } -func TestNewGenericProvider(t *testing.T) { - testCases := []struct { - name string - provider client.Object - expectError bool - expectedType genericprovider.GenericProvider - }{ - { - name: "create new generic provider from core provider", - provider: &operatorv1.CoreProvider{}, - expectedType: &genericprovider.CoreProviderWrapper{}, - }, - { - name: "create new generic provider from bootstrap provider", - provider: &operatorv1.BootstrapProvider{}, - expectedType: &genericprovider.BootstrapProviderWrapper{}, - }, - { - name: "create new generic provider from control plane provider", - provider: &operatorv1.ControlPlaneProvider{}, - expectedType: &genericprovider.ControlPlaneProviderWrapper{}, - }, - { - name: "create new generic provider from infrastructure plane provider", - provider: &operatorv1.InfrastructureProvider{}, - expectedType: &genericprovider.InfrastructureProviderWrapper{}, - }, - { - name: "fail to create new generic provider", - provider: &corev1.Pod{}, - expectError: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - g := NewWithT(t) - r := GenericProviderReconciler{ - Provider: tc.provider, - } - - genericProvider, err := r.newGenericProvider() - if tc.expectError { - g.Expect(err).To(HaveOccurred()) - } else { - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(reflect.TypeOf(genericProvider)).To(Equal(reflect.TypeOf(tc.expectedType))) - g.Expect(genericProvider.GetObject()).ToNot(BeIdenticalTo(tc.provider)) - } - }) - } -} - -func TestNewGenericProviderList(t *testing.T) { - testCases := []struct { - name string - providerList client.ObjectList - expectError bool - expectedType genericprovider.GenericProviderList - }{ - { - name: "create new generic provider from core provider", - providerList: &operatorv1.CoreProviderList{}, - expectedType: &genericprovider.CoreProviderListWrapper{}, - }, - { - name: "create new generic provider from bootstrap provider", - providerList: &operatorv1.BootstrapProviderList{}, - expectedType: &genericprovider.BootstrapProviderListWrapper{}, - }, - { - name: "create new generic provider from control plane provider", - providerList: &operatorv1.ControlPlaneProviderList{}, - expectedType: &genericprovider.ControlPlaneProviderListWrapper{}, - }, - { - name: "create new generic provider from infrastructure plane provider", - providerList: &operatorv1.InfrastructureProviderList{}, - expectedType: &genericprovider.InfrastructureProviderListWrapper{}, - }, - { - name: "fail to create new generic provider", - providerList: &corev1.PodList{}, - expectError: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - g := NewWithT(t) - r := GenericProviderReconciler{ - ProviderList: tc.providerList, - } - - genericProviderList, err := r.newGenericProviderList() - if tc.expectError { - g.Expect(err).To(HaveOccurred()) - } else { - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(reflect.TypeOf(genericProviderList)).To(Equal(reflect.TypeOf(tc.expectedType))) - g.Expect(genericProviderList.GetObject()).ToNot(BeIdenticalTo(tc.providerList)) - } - }) - } -} - func TestProviderSpecChanges(t *testing.T) { testCases := []struct { name string @@ -558,42 +443,48 @@ func TestProviderSpecChanges(t *testing.T) { updatedSpecHash, err := calculateHash(tc.updatedSpec) g.Expect(err).ToNot(HaveOccurred()) - provider := &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: tc.spec, - }, + provider := &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: tc.spec, }, } namespace := "test-provider-spec-changes" - t.Log("Ensure namespace exists", namespace) - g.Expect(env.EnsureNamespaceExists(ctx, namespace)).To(Succeed()) + ns, err := env.CreateNamespace(ctx, namespace) + t.Log("Ensure namespace exists", ns.Name) + g.Expect(err).ToNot(HaveOccurred()) - g.Expect(env.CreateAndWait(ctx, dummyConfigMap(namespace, testCurrentVersion))).To(Succeed()) + g.Expect(env.CreateAndWait(ctx, dummyConfigMap(ns.Name, testCurrentVersion))).To(Succeed()) - provider.SetNamespace(namespace) + provider.SetNamespace(ns.Name) t.Log("creating test provider", provider.GetName()) - g.Expect(env.CreateAndWait(ctx, provider.GetObject())).To(Succeed()) + g.Expect(env.CreateAndWait(ctx, provider.DeepCopy())).To(Succeed()) g.Eventually(generateExpectedResultChecker(provider, specHash, corev1.ConditionTrue), timeout).Should(BeEquivalentTo(true)) - // Change provider spec - provider.SetSpec(tc.updatedSpec) + g.Eventually(func() error { + if err := env.Client.Get(ctx, client.ObjectKeyFromObject(provider), provider); err != nil { + return err + } - // Set a label to ensure that provider was changed - labels := provider.GetLabels() - if labels == nil { - labels = map[string]string{} - } - labels["my-label"] = "some-value" - provider.SetLabels(labels) + // Change provider spec + provider.SetSpec(tc.updatedSpec) - g.Expect(env.Client.Update(ctx, provider.GetObject())).To(Succeed()) + // Set a label to ensure that provider was changed + labels := provider.GetLabels() + if labels == nil { + labels = map[string]string{} + } + labels["my-label"] = "some-value" + provider.SetLabels(labels) + provider.SetManagedFields(nil) + + return env.Client.Update(ctx, provider) + }).Should(Succeed()) if !tc.expectError { g.Eventually(generateExpectedResultChecker(provider, updatedSpecHash, corev1.ConditionTrue), timeout).Should(BeEquivalentTo(true)) @@ -602,22 +493,14 @@ func TestProviderSpecChanges(t *testing.T) { } // Clean up - objs := []client.Object{provider.GetObject()} - objs = append(objs, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Name: testCurrentVersion, - Namespace: namespace, - }, - }) - - g.Expect(env.CleanupAndWait(ctx, objs...)).To(Succeed()) + g.Expect(env.Cleanup(ctx, provider, ns)).To(Succeed()) }) } } -func generateExpectedResultChecker(provider *genericprovider.CoreProviderWrapper, specHash string, condStatus corev1.ConditionStatus) func() bool { +func generateExpectedResultChecker(provider genericprovider.GenericProvider, specHash string, condStatus corev1.ConditionStatus) func() bool { return func() bool { - if err := env.Get(ctx, client.ObjectKeyFromObject(provider.GetObject()), provider.GetObject()); err != nil { + if err := env.Get(ctx, client.ObjectKeyFromObject(provider), provider); err != nil { return false } diff --git a/internal/controller/healthcheck/healthcheck_controller.go b/internal/controller/healthcheck/healthcheck_controller.go index 1b5f14757..248beb6a3 100644 --- a/internal/controller/healthcheck/healthcheck_controller.go +++ b/internal/controller/healthcheck/healthcheck_controller.go @@ -26,7 +26,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" - "sigs.k8s.io/cluster-api-operator/internal/controller/genericprovider" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/patch" @@ -94,7 +93,7 @@ func (r *ProviderHealthCheckReconciler) Reconcile(ctx context.Context, req recon } // Initialize the patch helper - patchHelper, err := patch.NewHelper(typedProvider.GetObject(), r.Client) + patchHelper, err := patch.NewHelper(typedProvider, r.Client) if err != nil { return result, err } @@ -120,10 +119,10 @@ func (r *ProviderHealthCheckReconciler) Reconcile(ctx context.Context, req recon options := patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{clusterv1.ReadyCondition}} - return result, patchHelper.Patch(ctx, typedProvider.GetObject(), options) + return result, patchHelper.Patch(ctx, typedProvider, options) } -func (r *ProviderHealthCheckReconciler) getGenericProvider(ctx context.Context, providerKind, providerName, providerNamespace string) (genericprovider.GenericProvider, error) { +func (r *ProviderHealthCheckReconciler) getGenericProvider(ctx context.Context, providerKind, providerName, providerNamespace string) (operatorv1.GenericProvider, error) { switch providerKind { case "CoreProvider": provider := &operatorv1.CoreProvider{} @@ -131,35 +130,35 @@ func (r *ProviderHealthCheckReconciler) getGenericProvider(ctx context.Context, return nil, err } - return &genericprovider.CoreProviderWrapper{CoreProvider: provider}, nil + return provider, nil case "BootstrapProvider": provider := &operatorv1.BootstrapProvider{} if err := r.Client.Get(ctx, types.NamespacedName{Name: providerName, Namespace: providerNamespace}, provider); err != nil { return nil, err } - return &genericprovider.BootstrapProviderWrapper{BootstrapProvider: provider}, nil + return provider, nil case "ControlPlaneProvider": provider := &operatorv1.ControlPlaneProvider{} if err := r.Client.Get(ctx, types.NamespacedName{Name: providerName, Namespace: providerNamespace}, provider); err != nil { return nil, err } - return &genericprovider.ControlPlaneProviderWrapper{ControlPlaneProvider: provider}, nil + return provider, nil case "InfrastructureProvider": provider := &operatorv1.InfrastructureProvider{} if err := r.Client.Get(ctx, types.NamespacedName{Name: providerName, Namespace: providerNamespace}, provider); err != nil { return nil, err } - return &genericprovider.InfrastructureProviderWrapper{InfrastructureProvider: provider}, nil + return provider, nil case "AddonProvider": provider := &operatorv1.AddonProvider{} if err := r.Client.Get(ctx, types.NamespacedName{Name: providerName, Namespace: providerNamespace}, provider); err != nil { return nil, err } - return &genericprovider.AddonProviderWrapper{AddonProvider: provider}, nil + return provider, nil default: return nil, fmt.Errorf("failed to cast interface for type: %s", providerKind) } diff --git a/internal/controller/healthcheck/healthcheck_controller_test.go b/internal/controller/healthcheck/healthcheck_controller_test.go index 9049c2ef5..311d5966c 100644 --- a/internal/controller/healthcheck/healthcheck_controller_test.go +++ b/internal/controller/healthcheck/healthcheck_controller_test.go @@ -28,7 +28,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" - "sigs.k8s.io/cluster-api-operator/internal/controller/genericprovider" ) const ( @@ -73,7 +72,7 @@ spec: testCurrentVersion = "v0.4.2" ) -func insertDummyConfig(provider genericprovider.GenericProvider) { +func insertDummyConfig(provider operatorv1.GenericProvider) { spec := provider.GetSpec() spec.FetchConfig = &operatorv1.FetchConfiguration{ Selector: &metav1.LabelSelector{ @@ -122,15 +121,13 @@ func TestReconcilerReadyConditions(t *testing.T) { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - provider := &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: testCurrentVersion, - }, + provider := &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: testCurrentVersion, }, }, } @@ -142,7 +139,7 @@ func TestReconcilerReadyConditions(t *testing.T) { insertDummyConfig(provider) provider.SetNamespace(namespace) - g.Expect(env.CreateAndWait(ctx, provider.GetObject())).To(Succeed()) + g.Expect(env.CreateAndWait(ctx, provider)).To(Succeed()) g.Eventually(func() bool { deployment := &appsv1.Deployment{} @@ -169,7 +166,7 @@ func TestReconcilerReadyConditions(t *testing.T) { }, timeout).Should(BeTrue()) g.Eventually(func() bool { - if err := env.Get(ctx, client.ObjectKeyFromObject(provider.GetObject()), provider.GetObject()); err != nil { + if err := env.Get(ctx, client.ObjectKeyFromObject(provider), provider); err != nil { return false } @@ -185,7 +182,7 @@ func TestReconcilerReadyConditions(t *testing.T) { return false }, timeout).Should(BeTrue()) - objs := []client.Object{provider.GetObject()} + objs := []client.Object{provider} objs = append(objs, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ diff --git a/internal/controller/manifests_downloader_test.go b/internal/controller/manifests_downloader_test.go index 54d4c1346..8e1cbc29f 100644 --- a/internal/controller/manifests_downloader_test.go +++ b/internal/controller/manifests_downloader_test.go @@ -25,7 +25,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" - "sigs.k8s.io/cluster-api-operator/internal/controller/genericprovider" ) func TestManifestsDownloader(t *testing.T) { @@ -39,16 +38,14 @@ func TestManifestsDownloader(t *testing.T) { p := &phaseReconciler{ ctrlClient: fakeclient, - provider: &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - Namespace: namespace, - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.4.3", - }, + provider: &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + Namespace: namespace, + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.4.3", }, }, }, diff --git a/internal/controller/phases.go b/internal/controller/phases.go index edf7c0bea..466400d1f 100644 --- a/internal/controller/phases.go +++ b/internal/controller/phases.go @@ -504,9 +504,9 @@ func (p *phaseReconciler) delete(ctx context.Context) (reconcile.Result, error) return reconcile.Result{}, wrapPhaseError(err, operatorv1.OldComponentsDeletionErrorReason) } -func clusterctlProviderName(provider genericprovider.GenericProvider) client.ObjectKey { +func clusterctlProviderName(provider operatorv1.GenericProvider) client.ObjectKey { prefix := "" - switch provider.GetObject().(type) { + switch provider.(type) { case *operatorv1.BootstrapProvider: prefix = "bootstrap-" case *operatorv1.ControlPlaneProvider: diff --git a/internal/controller/phases_test.go b/internal/controller/phases_test.go index 1ff9633da..52c6f2db5 100644 --- a/internal/controller/phases_test.go +++ b/internal/controller/phases_test.go @@ -29,7 +29,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" - "sigs.k8s.io/cluster-api-operator/internal/controller/genericprovider" ) func TestSecretReader(t *testing.T) { @@ -43,25 +42,23 @@ func TestSecretReader(t *testing.T) { p := &phaseReconciler{ ctrlClient: fakeclient, - provider: &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - Namespace: namespace, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "CoreProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - ConfigSecret: &operatorv1.SecretReference{ - Name: secretName, - Namespace: secretNamespace, - }, - FetchConfig: &operatorv1.FetchConfiguration{ - URL: "https://example.com", - }, + provider: &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + Namespace: namespace, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "CoreProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + ConfigSecret: &operatorv1.SecretReference{ + Name: secretName, + Namespace: secretNamespace, + }, + FetchConfig: &operatorv1.FetchConfiguration{ + URL: "https://example.com", }, }, }, @@ -101,22 +98,20 @@ func TestSecretReader(t *testing.T) { } func TestConfigmapRepository(t *testing.T) { - provider := &genericprovider.InfrastructureProviderWrapper{ - InfrastructureProvider: &operatorv1.InfrastructureProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "aws", - Namespace: "ns1", - }, - TypeMeta: metav1.TypeMeta{ - Kind: "InfrastructureProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.InfrastructureProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - FetchConfig: &operatorv1.FetchConfiguration{ - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{"provider-components": "aws"}, - }, + provider := &operatorv1.InfrastructureProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "aws", + Namespace: "ns1", + }, + TypeMeta: metav1.TypeMeta{ + Kind: "InfrastructureProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.InfrastructureProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + FetchConfig: &operatorv1.FetchConfiguration{ + Selector: &metav1.LabelSelector{ + MatchLabels: map[string]string{"provider-components": "aws"}, }, }, }, @@ -374,7 +369,7 @@ metadata: t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - fakeclient := fake.NewClientBuilder().WithScheme(setupScheme()).WithObjects(provider.GetObject()).Build() + fakeclient := fake.NewClientBuilder().WithScheme(setupScheme()).WithObjects(provider).Build() p := &phaseReconciler{ ctrlClient: fakeclient, provider: provider, diff --git a/internal/controller/preflight_checks.go b/internal/controller/preflight_checks.go index 16f86afd2..b56f54996 100644 --- a/internal/controller/preflight_checks.go +++ b/internal/controller/preflight_checks.go @@ -143,7 +143,7 @@ func preflightChecks(ctx context.Context, c client.Client, provider genericprovi } } - if err := c.List(ctx, providerList.GetObject()); err != nil { + if err := c.List(ctx, providerList); err != nil { return ctrl.Result{}, fmt.Errorf("failed to list providers: %w", err) } diff --git a/internal/controller/preflight_checks_test.go b/internal/controller/preflight_checks_test.go index 930872a14..bb7b5b5e5 100644 --- a/internal/controller/preflight_checks_test.go +++ b/internal/controller/preflight_checks_test.go @@ -37,30 +37,28 @@ func TestPreflightChecks(t *testing.T) { testCases := []struct { name string - providers []genericprovider.GenericProvider + providers []operatorv1.GenericProvider providerList genericprovider.GenericProviderList expectedCondition clusterv1.Condition expectedError bool }{ { name: "only one core provider exists, preflight check passed", - providers: []genericprovider.GenericProvider{ - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "CoreProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - FetchConfig: &operatorv1.FetchConfiguration{ - URL: "https://example.com", - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "CoreProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", + FetchConfig: &operatorv1.FetchConfiguration{ + URL: "https://example.com", }, }, }, @@ -70,30 +68,26 @@ func TestPreflightChecks(t *testing.T) { Type: operatorv1.PreflightCheckCondition, Status: corev1.ConditionTrue, }, - providerList: &genericprovider.CoreProviderListWrapper{ - CoreProviderList: &operatorv1.CoreProviderList{}, - }, + providerList: &operatorv1.CoreProviderList{}, }, { name: "core provider with incorrect name, preflight check failed", expectedError: true, - providers: []genericprovider.GenericProvider{ - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "my-fancy-cluster-api", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "CoreProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - FetchConfig: &operatorv1.FetchConfiguration{ - URL: "https://example.com", - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-fancy-cluster-api", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "CoreProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", + FetchConfig: &operatorv1.FetchConfiguration{ + URL: "https://example.com", }, }, }, @@ -106,45 +100,39 @@ func TestPreflightChecks(t *testing.T) { Message: "Incorrect CoreProvider name: my-fancy-cluster-api. It should be cluster-api", Status: corev1.ConditionFalse, }, - providerList: &genericprovider.CoreProviderListWrapper{ - CoreProviderList: &operatorv1.CoreProviderList{}, - }, + providerList: &operatorv1.CoreProviderList{}, }, { name: "two core providers were created, preflight check failed", expectedError: true, - providers: []genericprovider.GenericProvider{ - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "CoreProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "CoreProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "core-3", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "CoreProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "core-3", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "CoreProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, @@ -156,45 +144,39 @@ func TestPreflightChecks(t *testing.T) { Message: moreThanOneCoreProviderInstanceExistsMessage, Status: corev1.ConditionFalse, }, - providerList: &genericprovider.CoreProviderListWrapper{ - CoreProviderList: &operatorv1.CoreProviderList{}, - }, + providerList: &operatorv1.CoreProviderList{}, }, { name: "two core providers in two different namespaces were created, preflight check failed", expectedError: true, - providers: []genericprovider.GenericProvider{ - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "CoreProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "CoreProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - Namespace: namespaceName2, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "CoreProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + Namespace: namespaceName2, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "CoreProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, @@ -206,53 +188,47 @@ func TestPreflightChecks(t *testing.T) { Message: moreThanOneCoreProviderInstanceExistsMessage, Status: corev1.ConditionFalse, }, - providerList: &genericprovider.CoreProviderListWrapper{ - CoreProviderList: &operatorv1.CoreProviderList{}, - }, + providerList: &operatorv1.CoreProviderList{}, }, { name: "only one infra provider exists, preflight check passed", - providers: []genericprovider.GenericProvider{ - &genericprovider.InfrastructureProviderWrapper{ - InfrastructureProvider: &operatorv1.InfrastructureProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "aws", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "InfrastructureProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.InfrastructureProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.InfrastructureProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "aws", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "InfrastructureProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.InfrastructureProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - Namespace: namespaceName2, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "CoreProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha4", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + Namespace: namespaceName2, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "CoreProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha4", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, - Status: operatorv1.CoreProviderStatus{ - ProviderStatus: operatorv1.ProviderStatus{ - Conditions: []clusterv1.Condition{ - { - Type: clusterv1.ReadyCondition, - Status: corev1.ConditionTrue, - LastTransitionTime: metav1.Now(), - }, + }, + Status: operatorv1.CoreProviderStatus{ + ProviderStatus: operatorv1.ProviderStatus{ + Conditions: []clusterv1.Condition{ + { + Type: clusterv1.ReadyCondition, + Status: corev1.ConditionTrue, + LastTransitionTime: metav1.Now(), }, }, }, @@ -263,70 +239,62 @@ func TestPreflightChecks(t *testing.T) { Type: operatorv1.PreflightCheckCondition, Status: corev1.ConditionTrue, }, - providerList: &genericprovider.InfrastructureProviderListWrapper{ - InfrastructureProviderList: &operatorv1.InfrastructureProviderList{}, - }, + providerList: &operatorv1.InfrastructureProviderList{}, }, { name: "two different infra providers exist in same namespaces, preflight check passed", - providers: []genericprovider.GenericProvider{ - &genericprovider.InfrastructureProviderWrapper{ - InfrastructureProvider: &operatorv1.InfrastructureProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "metal3", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "InfrastructureProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.InfrastructureProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.InfrastructureProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "metal3", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "InfrastructureProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.InfrastructureProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, - &genericprovider.InfrastructureProviderWrapper{ - InfrastructureProvider: &operatorv1.InfrastructureProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "aws", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "InfrastructureProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.InfrastructureProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + &operatorv1.InfrastructureProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "aws", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "InfrastructureProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.InfrastructureProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - Namespace: namespaceName2, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "CoreProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha4", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + Namespace: namespaceName2, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "CoreProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha4", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, - Status: operatorv1.CoreProviderStatus{ - ProviderStatus: operatorv1.ProviderStatus{ - Conditions: []clusterv1.Condition{ - { - Type: clusterv1.ReadyCondition, - Status: corev1.ConditionTrue, - LastTransitionTime: metav1.Now(), - }, + }, + Status: operatorv1.CoreProviderStatus{ + ProviderStatus: operatorv1.ProviderStatus{ + Conditions: []clusterv1.Condition{ + { + Type: clusterv1.ReadyCondition, + Status: corev1.ConditionTrue, + LastTransitionTime: metav1.Now(), }, }, }, @@ -337,70 +305,62 @@ func TestPreflightChecks(t *testing.T) { Type: operatorv1.PreflightCheckCondition, Status: corev1.ConditionTrue, }, - providerList: &genericprovider.InfrastructureProviderListWrapper{ - InfrastructureProviderList: &operatorv1.InfrastructureProviderList{}, - }, + providerList: &operatorv1.InfrastructureProviderList{}, }, { name: "two different infra providers exist in different namespaces, preflight check passed", - providers: []genericprovider.GenericProvider{ - &genericprovider.InfrastructureProviderWrapper{ - InfrastructureProvider: &operatorv1.InfrastructureProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "metal3", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "InfrastructureProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.InfrastructureProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.InfrastructureProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "metal3", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "InfrastructureProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.InfrastructureProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, - &genericprovider.InfrastructureProviderWrapper{ - InfrastructureProvider: &operatorv1.InfrastructureProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "aws", - Namespace: namespaceName2, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "InfrastructureProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.InfrastructureProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + &operatorv1.InfrastructureProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "aws", + Namespace: namespaceName2, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "InfrastructureProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.InfrastructureProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - Namespace: namespaceName2, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "CoreProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha4", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + Namespace: namespaceName2, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "CoreProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha4", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, - Status: operatorv1.CoreProviderStatus{ - ProviderStatus: operatorv1.ProviderStatus{ - Conditions: []clusterv1.Condition{ - { - Type: clusterv1.ReadyCondition, - Status: corev1.ConditionTrue, - LastTransitionTime: metav1.Now(), - }, + }, + Status: operatorv1.CoreProviderStatus{ + ProviderStatus: operatorv1.ProviderStatus{ + Conditions: []clusterv1.Condition{ + { + Type: clusterv1.ReadyCondition, + Status: corev1.ConditionTrue, + LastTransitionTime: metav1.Now(), }, }, }, @@ -411,45 +371,39 @@ func TestPreflightChecks(t *testing.T) { Type: operatorv1.PreflightCheckCondition, Status: corev1.ConditionTrue, }, - providerList: &genericprovider.InfrastructureProviderListWrapper{ - InfrastructureProviderList: &operatorv1.InfrastructureProviderList{}, - }, + providerList: &operatorv1.InfrastructureProviderList{}, }, { name: "two similar infra provider exist in different namespaces, preflight check failed", expectedError: true, - providers: []genericprovider.GenericProvider{ - &genericprovider.InfrastructureProviderWrapper{ - InfrastructureProvider: &operatorv1.InfrastructureProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "aws", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "InfrastructureProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.InfrastructureProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.InfrastructureProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "aws", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "InfrastructureProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.InfrastructureProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, - &genericprovider.InfrastructureProviderWrapper{ - InfrastructureProvider: &operatorv1.InfrastructureProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "aws", - Namespace: namespaceName2, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "InfrastructureProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.InfrastructureProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + &operatorv1.InfrastructureProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "aws", + Namespace: namespaceName2, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "InfrastructureProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.InfrastructureProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, @@ -461,28 +415,24 @@ func TestPreflightChecks(t *testing.T) { Message: fmt.Sprintf(moreThanOneProviderInstanceExistsMessage, "aws", namespaceName2), Status: corev1.ConditionFalse, }, - providerList: &genericprovider.InfrastructureProviderListWrapper{ - InfrastructureProviderList: &operatorv1.InfrastructureProviderList{}, - }, + providerList: &operatorv1.InfrastructureProviderList{}, }, { name: "wrong version, preflight check failed", expectedError: true, - providers: []genericprovider.GenericProvider{ - &genericprovider.InfrastructureProviderWrapper{ - InfrastructureProvider: &operatorv1.InfrastructureProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "aws", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "InfrastructureProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.InfrastructureProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "one", - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.InfrastructureProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "aws", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "InfrastructureProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.InfrastructureProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "one", }, }, }, @@ -494,28 +444,24 @@ func TestPreflightChecks(t *testing.T) { Message: "could not parse \"one\" as version", Status: corev1.ConditionFalse, }, - providerList: &genericprovider.InfrastructureProviderListWrapper{ - InfrastructureProviderList: &operatorv1.InfrastructureProviderList{}, - }, + providerList: &operatorv1.InfrastructureProviderList{}, }, { name: "missing version, preflight check passed", - providers: []genericprovider.GenericProvider{ - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "CoreProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - FetchConfig: &operatorv1.FetchConfiguration{ - URL: "https://example.com", - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "CoreProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + FetchConfig: &operatorv1.FetchConfiguration{ + URL: "https://example.com", }, }, }, @@ -525,32 +471,28 @@ func TestPreflightChecks(t *testing.T) { Type: operatorv1.PreflightCheckCondition, Status: corev1.ConditionTrue, }, - providerList: &genericprovider.CoreProviderListWrapper{ - CoreProviderList: &operatorv1.CoreProviderList{}, - }, + providerList: &operatorv1.CoreProviderList{}, }, { name: "incorrect fetchConfig, preflight check failed", expectedError: true, - providers: []genericprovider.GenericProvider{ - &genericprovider.InfrastructureProviderWrapper{ - InfrastructureProvider: &operatorv1.InfrastructureProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "aws", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "InfrastructureProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.InfrastructureProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - FetchConfig: &operatorv1.FetchConfiguration{ - URL: "https://example.com", - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{"provider-components": "aws"}, - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.InfrastructureProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "aws", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "InfrastructureProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.InfrastructureProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", + FetchConfig: &operatorv1.FetchConfiguration{ + URL: "https://example.com", + Selector: &metav1.LabelSelector{ + MatchLabels: map[string]string{"provider-components": "aws"}, }, }, }, @@ -564,27 +506,23 @@ func TestPreflightChecks(t *testing.T) { Message: "Only one of Selector and URL must be provided, not both", Status: corev1.ConditionFalse, }, - providerList: &genericprovider.InfrastructureProviderListWrapper{ - InfrastructureProviderList: &operatorv1.InfrastructureProviderList{}, - }, + providerList: &operatorv1.InfrastructureProviderList{}, }, { name: "predefined Core Provider without fetch config, preflight check passed", - providers: []genericprovider.GenericProvider{ - &genericprovider.CoreProviderWrapper{ - CoreProvider: &operatorv1.CoreProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-api", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "CoreProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.CoreProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.CoreProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster-api", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "CoreProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.CoreProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, @@ -593,28 +531,24 @@ func TestPreflightChecks(t *testing.T) { Type: operatorv1.PreflightCheckCondition, Status: corev1.ConditionTrue, }, - providerList: &genericprovider.CoreProviderListWrapper{ - CoreProviderList: &operatorv1.CoreProviderList{}, - }, + providerList: &operatorv1.CoreProviderList{}, }, { name: "custom Infrastructure Provider without fetch config, preflight check failed", expectedError: true, - providers: []genericprovider.GenericProvider{ - &genericprovider.InfrastructureProviderWrapper{ - InfrastructureProvider: &operatorv1.InfrastructureProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "my-custom-aws", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "InfrastructureProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.InfrastructureProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.InfrastructureProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-custom-aws", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "InfrastructureProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.InfrastructureProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", }, }, }, @@ -626,31 +560,27 @@ func TestPreflightChecks(t *testing.T) { Message: "Either Selector or URL must be provided for a not predefined provider", Status: corev1.ConditionFalse, }, - providerList: &genericprovider.CoreProviderListWrapper{ - CoreProviderList: &operatorv1.CoreProviderList{}, - }, + providerList: &operatorv1.CoreProviderList{}, }, { name: "custom Infrastructure Provider with fetch config with empty values, preflight check failed", expectedError: true, - providers: []genericprovider.GenericProvider{ - &genericprovider.InfrastructureProviderWrapper{ - InfrastructureProvider: &operatorv1.InfrastructureProvider{ - ObjectMeta: metav1.ObjectMeta{ - Name: "my-custom-aws", - Namespace: namespaceName1, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "InfrastructureProvider", - APIVersion: "operator.cluster.x-k8s.io/v1alpha1", - }, - Spec: operatorv1.InfrastructureProviderSpec{ - ProviderSpec: operatorv1.ProviderSpec{ - Version: "v1.0.0", - FetchConfig: &operatorv1.FetchConfiguration{ - URL: "", - Selector: nil, - }, + providers: []operatorv1.GenericProvider{ + &operatorv1.InfrastructureProvider{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-custom-aws", + Namespace: namespaceName1, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "InfrastructureProvider", + APIVersion: "operator.cluster.x-k8s.io/v1alpha1", + }, + Spec: operatorv1.InfrastructureProviderSpec{ + ProviderSpec: operatorv1.ProviderSpec{ + Version: "v1.0.0", + FetchConfig: &operatorv1.FetchConfiguration{ + URL: "", + Selector: nil, }, }, }, @@ -663,9 +593,7 @@ func TestPreflightChecks(t *testing.T) { Message: "Either Selector or URL must be provided for a not predefined provider", Status: corev1.ConditionFalse, }, - providerList: &genericprovider.CoreProviderListWrapper{ - CoreProviderList: &operatorv1.CoreProviderList{}, - }, + providerList: &operatorv1.CoreProviderList{}, }, } @@ -676,7 +604,7 @@ func TestPreflightChecks(t *testing.T) { fakeclient := fake.NewClientBuilder().WithObjects().Build() for _, c := range tc.providers { - gs.Expect(fakeclient.Create(ctx, c.GetObject())).To(Succeed()) + gs.Expect(fakeclient.Create(ctx, c)).To(Succeed()) } _, err := preflightChecks(context.Background(), fakeclient, tc.providers[0], tc.providerList) diff --git a/internal/envtest/environment.go b/internal/envtest/environment.go index 10b374932..0b98d090f 100644 --- a/internal/envtest/environment.go +++ b/internal/envtest/environment.go @@ -109,6 +109,10 @@ func New(uncachedObjs ...client.Object) *Environment { crdPaths = append(crdPaths, capiPath) } + if err := operatorv1.AddToScheme(scheme.Scheme); err != nil { + klog.Fatalf("Failed to set scheme for manager: %v", err) + } + // Create the test environment. env := &envtest.Environment{ Scheme: scheme.Scheme, diff --git a/util/util.go b/util/util.go index c9aac381b..ac44f2d29 100644 --- a/util/util.go +++ b/util/util.go @@ -23,13 +23,13 @@ import ( ) func IsCoreProvider(p genericprovider.GenericProvider) bool { - _, ok := p.GetObject().(*operatorv1.CoreProvider) + _, ok := p.(*operatorv1.CoreProvider) return ok } // ClusterctlProviderType returns the provider type from the genericProvider. -func ClusterctlProviderType(genericProvider genericprovider.GenericProvider) clusterctlv1.ProviderType { - switch genericProvider.GetObject().(type) { +func ClusterctlProviderType(genericProvider operatorv1.GenericProvider) clusterctlv1.ProviderType { + switch genericProvider.(type) { case *operatorv1.CoreProvider: return clusterctlv1.CoreProviderType case *operatorv1.ControlPlaneProvider: