Skip to content

Commit

Permalink
Merge pull request #5280 from hasueki/fix-nto-reconcile
Browse files Browse the repository at this point in the history
OCPBUGS-46354: fix(ho): Add all supported config schemas for NodePool NTO reconcile
  • Loading branch information
openshift-merge-bot[bot] authored Dec 20, 2024
2 parents 04b85e8 + ad2f927 commit 5f05b35
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hypershift-operator/controllers/nodepool/nto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
85 changes: 85 additions & 0 deletions hypershift-operator/controllers/nodepool/nto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}
}

0 comments on commit 5f05b35

Please sign in to comment.