Skip to content

Commit

Permalink
🐛 Separate k8s versions for management and child clusters, add a sepa…
Browse files Browse the repository at this point in the history
…rate group for v2prov testing. (#354)

* Separate kubernetes version under domains

Signed-off-by: Danil Grigorev <danil.grigorev@suse.com>

* Prevent duplicate provider sync to the same object

Signed-off-by: Danil Grigorev <danil.grigorev@suse.com>

---------

Signed-off-by: Danil Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev authored Jan 23, 2024
1 parent 81ca0ea commit 8109fda
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 23 deletions.
7 changes: 4 additions & 3 deletions internal/sync/provider_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewProviderSync(cl client.Client, capiProvider *turtlesv1.CAPIProvider) Syn
template := ProviderSync{}.Template(capiProvider)

destination, ok := template.(api.Provider)
if !ok {
if !ok || destination == nil {
return nil
}

Expand All @@ -66,8 +66,9 @@ func (ProviderSync) Template(capiProvider *turtlesv1.CAPIProvider) client.Object

for _, provider := range turtlesv1.Providers {
if provider.GetType() == strings.ToLower(string(capiProvider.Spec.Type)) {
provider := provider
template = provider
// We always know the template type, so we can safely typecast.
//nolint: forcetypeassert
template = provider.DeepCopyObject().(api.Provider)

template.SetName(meta.Name)
template.SetNamespace(meta.Namespace)
Expand Down
75 changes: 69 additions & 6 deletions internal/sync/provider_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/rancher-sandbox/rancher-turtles/internal/sync"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -31,10 +32,13 @@ import (

var _ = Describe("Provider sync", func() {
var (
err error
ns *corev1.Namespace
capiProvider *turtlesv1.CAPIProvider
infrastructure *operatorv1.InfrastructureProvider
err error
ns *corev1.Namespace
otherNs *corev1.Namespace
capiProvider *turtlesv1.CAPIProvider
capiProviderDuplicate *turtlesv1.CAPIProvider
infrastructure *operatorv1.InfrastructureProvider
infrastructureDuplicate *operatorv1.InfrastructureProvider
)

BeforeEach(func() {
Expand All @@ -44,6 +48,9 @@ var _ = Describe("Provider sync", func() {
ns, err = testEnv.CreateNamespace(ctx, "ns")
Expect(err).ToNot(HaveOccurred())

otherNs, err = testEnv.CreateNamespace(ctx, "other")
Expect(err).ToNot(HaveOccurred())

capiProvider = &turtlesv1.CAPIProvider{ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: ns.Name,
Expand All @@ -52,16 +59,25 @@ var _ = Describe("Provider sync", func() {
Type: turtlesv1.Infrastructure,
}}

capiProviderDuplicate = capiProvider.DeepCopy()
capiProviderDuplicate.Namespace = otherNs.Name

infrastructure = &operatorv1.InfrastructureProvider{ObjectMeta: metav1.ObjectMeta{
Name: string(capiProvider.Spec.Name),
Namespace: capiProvider.Namespace,
Namespace: ns.Name,
}}

infrastructureDuplicate = &operatorv1.InfrastructureProvider{ObjectMeta: metav1.ObjectMeta{
Name: string(capiProvider.Spec.Name),
Namespace: otherNs.Name,
}}

Expect(testEnv.Client.Create(ctx, capiProvider)).To(Succeed())
Expect(testEnv.Client.Create(ctx, capiProviderDuplicate)).To(Succeed())
})

AfterEach(func() {
testEnv.Cleanup(ctx, ns)
testEnv.Cleanup(ctx, ns, otherNs)
})

It("Should sync spec down", func() {
Expand Down Expand Up @@ -103,4 +119,51 @@ var _ = Describe("Provider sync", func() {
Expect(capiProvider).To(HaveField("Status.ProviderStatus", Equal(infrastructure.Status.ProviderStatus)))
Expect(capiProvider).To(HaveField("Status.Phase", Equal(turtlesv1.Provisioning)))
})

It("Should individually sync every provider", func() {
Expect(testEnv.Client.Create(ctx, infrastructure.DeepCopy())).To(Succeed())
Eventually(UpdateStatus(infrastructure, func() {
infrastructure.Status = operatorv1.InfrastructureProviderStatus{
ProviderStatus: operatorv1.ProviderStatus{
InstalledVersion: ptr.To("v1.2.3"),
},
}
})).Should(Succeed())

s := sync.NewProviderSync(testEnv, capiProvider)

Eventually(func() (err error) {
err = s.Get(ctx)
if err != nil {
return
}
err = s.Sync(ctx)
s.Apply(ctx, &err)
return
}).Should(Succeed())

Expect(capiProvider).To(HaveField("Status.ProviderStatus", Equal(infrastructure.Status.ProviderStatus)))
Expect(capiProvider).To(HaveField("Status.Phase", Equal(turtlesv1.Provisioning)))

s = sync.NewProviderSync(testEnv, capiProviderDuplicate)

Eventually(func() (err error) {
err = s.Get(ctx)
if err != nil {
return
}
err = s.Sync(ctx)
s.Apply(ctx, &err)
if err != nil {
return
}

obj := &operatorv1.InfrastructureProvider{}
err = testEnv.Get(ctx, client.ObjectKeyFromObject(infrastructureDuplicate), obj)
return
}).Should(Succeed())

Expect(capiProviderDuplicate).To(HaveField("Status.Phase", Equal(turtlesv1.Provisioning)))
Expect(capiProviderDuplicate).To(HaveField("Status.ProviderStatus.InstalledVersion", BeNil()))
})
})
5 changes: 4 additions & 1 deletion test/e2e/config/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ intervals:

variables:
RANCHER_VERSION: "v2.8.0"
RANCHER_LEGACY_VERSION: "v2.7.7"
KUBERNETES_VERSION: "v1.27.0"
KUBERNETES_MANAGEMENT_VERSION: "v1.27.0"
KUBERNETES_MANAGEMENT_LEGACY_VERSION: "v1.26.3"
RANCHER_HOSTNAME: "localhost"
RANCHER_FEATURES: ""
RANCHER_PATH: "rancher-latest/rancher"
KUBERNETES_VERSION: "v1.27.0"
CPI_IMAGE_K8S_VERSION: "v1.27.0"
RKE2_VERSION: "v1.26.8+rke2r1"
CAPI_CORE: "cluster-api:v1.4.6"
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ const (
)

const (
KubernetesManagementVersionVar = "KUBERNETES_MANAGEMENT_VERSION"
KubernetesManagementLegacyVersionVar = "KUBERNETES_MANAGEMENT_LEGACY_VERSION"
RancherLegacyVersionVar = "RANCHER_LEGACY_VERSION"

KubernetesVersionVar = "KUBERNETES_VERSION"
RancherFeaturesVar = "RANCHER_FEATURES"
RancherHostnameVar = "RANCHER_HOSTNAME"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/import_gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func CreateUsingGitOpsSpec(ctx context.Context, inputGetter func() CreateUsingGi
Expect(input.ClusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling %s spec", specName)
Expect(os.MkdirAll(input.ArtifactFolder, 0750)).To(Succeed(), "Invalid argument. input.ArtifactFolder can't be created for %s spec", specName)

Expect(input.E2EConfig.Variables).To(HaveKey(e2e.KubernetesVersionVar))
Expect(input.E2EConfig.Variables).To(HaveKey(e2e.KubernetesManagementVersionVar))
namespace, cancelWatches = e2e.SetupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder)
repoName = e2e.CreateRepoName(specName)

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suites/embedded-capi-disabled/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var _ = BeforeSuite(func() {
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
Hostname: hostName,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesVersionVar),
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
})
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suites/import-gitops/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var _ = BeforeSuite(func() {
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
Hostname: hostName,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesVersionVar),
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
})
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/suites/update-labels/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var _ = BeforeSuite(func() {
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
Hostname: hostName,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesVersionVar),
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementLegacyVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
})
Expand Down Expand Up @@ -143,10 +143,10 @@ var _ = BeforeSuite(func() {
HelmBinaryPath: flagVals.HelmBinaryPath,
HelmExtraValuesPath: filepath.Join(flagVals.HelmExtraValuesDir, "deploy-rancher.yaml"),
InstallCertManager: false,
RancherChartRepoName: "rancher-latest",
RancherChartURL: "https://releases.rancher.com/server-charts/latest",
RancherChartPath: "rancher-latest/rancher",
RancherVersion: "2.7.7",
RancherChartRepoName: e2eConfig.GetVariable(e2e.RancherRepoNameVar),
RancherChartURL: e2eConfig.GetVariable(e2e.RancherUrlVar),
RancherChartPath: e2eConfig.GetVariable(e2e.RancherPathVar),
RancherVersion: e2eConfig.GetVariable(e2e.RancherLegacyVersionVar),
RancherHost: hostName,
RancherNamespace: e2e.RancherNamespace,
RancherPassword: e2eConfig.GetVariable(e2e.RancherPasswordVar),
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/suites/v2prov/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var _ = BeforeSuite(func() {
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
Hostname: hostName,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesVersionVar),
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementLegacyVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
})
Expand Down Expand Up @@ -128,10 +128,10 @@ var _ = BeforeSuite(func() {
CertManagerChartPath: e2eConfig.GetVariable(e2e.CertManagerPathVar),
CertManagerUrl: e2eConfig.GetVariable(e2e.CertManagerUrlVar),
CertManagerRepoName: e2eConfig.GetVariable(e2e.CertManagerRepoNameVar),
RancherChartRepoName: "rancher-latest",
RancherChartURL: "https://releases.rancher.com/server-charts/latest",
RancherChartPath: "rancher-latest/rancher",
RancherVersion: "v2.7.7",
RancherChartRepoName: e2eConfig.GetVariable(e2e.RancherRepoNameVar),
RancherChartURL: e2eConfig.GetVariable(e2e.RancherUrlVar),
RancherChartPath: e2eConfig.GetVariable(e2e.RancherPathVar),
RancherVersion: e2eConfig.GetVariable(e2e.RancherLegacyVersionVar),
Development: true,
RancherHost: hostName,
RancherNamespace: e2e.RancherNamespace,
Expand Down

0 comments on commit 8109fda

Please sign in to comment.