From ad2f927dd2133b3aabaca84c9efafa64b63d8644 Mon Sep 17 00:00:00 2001 From: Hidematsu Sueki Date: Thu, 12 Dec 2024 13:57:17 -0500 Subject: [PATCH] fix(ho): Add all supported config schemas for NodePool NTO reconcile --- .../controllers/nodepool/nto.go | 6 ++ .../controllers/nodepool/nto_test.go | 85 +++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/hypershift-operator/controllers/nodepool/nto.go b/hypershift-operator/controllers/nodepool/nto.go index 01ed9a78b0..77d0956214 100644 --- a/hypershift-operator/controllers/nodepool/nto.go +++ b/hypershift-operator/controllers/nodepool/nto.go @@ -11,7 +11,10 @@ import ( "strings" "github.com/go-logr/logr" + configv1 "github.com/openshift/api/config/v1" + configv1alpha1 "github.com/openshift/api/config/v1alpha1" mcfgv1 "github.com/openshift/api/machineconfiguration/v1" + "github.com/openshift/api/operator/v1alpha1" performanceprofilev2 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/performanceprofile/v2" tunedv1 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1" hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1" @@ -414,6 +417,9 @@ func BuildMirrorConfigs(ctx context.Context, cg *ConfigGenerator) ([]*MirrorConf func getMirrorConfigForManifest(manifest []byte) (*MirrorConfig, error) { scheme := runtime.NewScheme() _ = mcfgv1.Install(scheme) + _ = v1alpha1.Install(scheme) + _ = configv1.Install(scheme) + _ = configv1alpha1.Install(scheme) yamlSerializer := serializer.NewSerializerWithOptions( serializer.DefaultMetaFactory, scheme, scheme, diff --git a/hypershift-operator/controllers/nodepool/nto_test.go b/hypershift-operator/controllers/nodepool/nto_test.go index 665e0cdbd6..753876a080 100644 --- a/hypershift-operator/controllers/nodepool/nto_test.go +++ b/hypershift-operator/controllers/nodepool/nto_test.go @@ -1011,3 +1011,88 @@ func makePerformanceProfileStatusAsString(opts ...func(*performanceprofilev2.Per b, _ := yaml.Marshal(status) return string(b) } + +func TestGetMirrorConfigForManifest(t *testing.T) { + machineConfig := ` +apiVersion: machineconfiguration.openshift.io/v1 +kind: MachineConfig +metadata: + labels: + machineconfiguration.openshift.io/role: worker + name: valid-machineconfig +spec: + config: + ignition: + version: 2.2.0 + storage: + files: + - contents: + source: data:text/plain;base64,dGhyb3dhd2F5Cg== + filesystem: root + mode: 493 + path: /some/path +` + + containerRuntimeConfig := ` +apiVersion: machineconfiguration.openshift.io/v1 +kind: ContainerRuntimeConfig +metadata: + name: valid-containerruntimeconfig +spec: + containerRuntimeConfig: + defaultRuntime: crun +` + + kubeletConfig := ` +apiVersion: machineconfiguration.openshift.io/v1 +kind: KubeletConfig +metadata: + name: valid-kubeletconfig +spec: + kubeletConfig: + maxPods: 100 +` + + imageDigestMirrorSet := ` +apiVersion: config.openshift.io/v1 +kind: ImageDigestMirrorSet +metadata: + name: valid-idms +spec: + imageDigestMirrors: + - mirrorSourcePolicy: AllowContactingSource + mirrors: + - some.registry.io/registry-redhat-io + source: registry.redhat.io +` + + testCases := []struct { + name string + input []byte + }{ + { + name: "Valid MachineConfig", + input: []byte(machineConfig), + }, + { + name: "Valid ContainerRuntimeConfig", + input: []byte(containerRuntimeConfig), + }, + { + name: "Valid KubeletConfig", + input: []byte(kubeletConfig), + }, + { + name: "Valid ImageDigestMirrorSet", + input: []byte(imageDigestMirrorSet), + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + g := NewWithT(t) + _, err := getMirrorConfigForManifest(tc.input) + g.Expect(err).To(BeNil()) + }) + } +}