Skip to content

Commit

Permalink
fix custom featuregates and add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
rphillips committed Jan 21, 2021
1 parent f9b204b commit 4c77ed7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
4 changes: 4 additions & 0 deletions pkg/controller/kubelet-config/helpers.go
Expand Up @@ -11,6 +11,7 @@ import (
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
Expand Down Expand Up @@ -72,6 +73,9 @@ func createNewKubeletIgnition(jsonConfig []byte) *ign3types.File {

func createNewDefaultFeatureGate() *osev1.FeatureGate {
return &osev1.FeatureGate{
ObjectMeta: metav1.ObjectMeta{
Name: clusterFeatureInstanceName,
},
Spec: osev1.FeatureGateSpec{
FeatureGateSelection: osev1.FeatureGateSelection{
FeatureSet: osev1.Default,
Expand Down
11 changes: 4 additions & 7 deletions pkg/controller/kubelet-config/kubelet_config_features.go
Expand Up @@ -51,13 +51,8 @@ func (ctrl *Controller) syncFeatureHandler(key string) error {
glog.V(4).Infof("Finished syncing feature handler %q (%v)", key, time.Since(startTime))
}()

_, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
return err
}

// Fetch the Feature
features, err := ctrl.featLister.Get(name)
features, err := ctrl.featLister.Get(clusterFeatureInstanceName)
if errors.IsNotFound(err) {
glog.V(2).Infof("FeatureSet %v is missing, using default", key)
features = &osev1.FeatureGate{
Expand Down Expand Up @@ -131,8 +126,10 @@ func (ctrl *Controller) syncFeatureHandler(key string) error {
if err != nil {
return err
}
tempIgnConfig := ctrlcommon.NewIgnConfig()
cfgIgn := createNewKubeletIgnition(cfgJSON)
rawCfgIgn, err := json.Marshal(cfgIgn)
tempIgnConfig.Storage.Files = append(tempIgnConfig.Storage.Files, *cfgIgn)
rawCfgIgn, err := json.Marshal(tempIgnConfig)
if err != nil {
return err
}
Expand Down
52 changes: 52 additions & 0 deletions pkg/controller/kubelet-config/kubelet_config_features_test.go
Expand Up @@ -6,7 +6,9 @@ import (

ign3types "github.com/coreos/ignition/v2/config/v3_2/types"
configv1 "github.com/openshift/api/config/v1"
osev1 "github.com/openshift/api/config/v1"
"github.com/vincent-petithory/dataurl"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
"github.com/openshift/machine-config-operator/test/helpers"
Expand Down Expand Up @@ -72,3 +74,53 @@ func TestFeaturesDefault(t *testing.T) {
})
}
}

func TestFeaturesCustomNoUpgrade(t *testing.T) {
for _, platform := range []configv1.PlatformType{configv1.AWSPlatformType, configv1.NonePlatformType, "unrecognized"} {
t.Run(string(platform), func(t *testing.T) {
f := newFixture(t)

cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform)
mcp := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0")
mcp2 := helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0")
kubeletConfigKey1, _ := getManagedKubeletConfigKey(mcp, nil)
kubeletConfigKey2, _ := getManagedKubeletConfigKey(mcp2, nil)
mcs := helpers.NewMachineConfig(kubeletConfigKey1, map[string]string{"node-role/master": ""}, "dummy://", []ign3types.File{{}})
mcs2 := helpers.NewMachineConfig(kubeletConfigKey2, map[string]string{"node-role/worker": ""}, "dummy://", []ign3types.File{{}})
mcsDeprecated := mcs.DeepCopy()
mcsDeprecated.Name = getManagedFeaturesKeyDeprecated(mcp)
mcs2Deprecated := mcs2.DeepCopy()
mcs2Deprecated.Name = getManagedFeaturesKeyDeprecated(mcp2)

f.ccLister = append(f.ccLister, cc)
f.mcpLister = append(f.mcpLister, mcp)
f.mcpLister = append(f.mcpLister, mcp2)

features := &osev1.FeatureGate{
ObjectMeta: metav1.ObjectMeta{
Name: clusterFeatureInstanceName,
},
Spec: osev1.FeatureGateSpec{
FeatureGateSelection: osev1.FeatureGateSelection{
FeatureSet: osev1.CustomNoUpgrade,
CustomNoUpgrade: &osev1.CustomFeatureGates{
Enabled: []string{"CSIMigration"},
},
},
},
}

f.featLister = append(f.featLister, features)

f.expectGetMachineConfigAction(mcs)
f.expectGetMachineConfigAction(mcsDeprecated)
f.expectGetMachineConfigAction(mcs)
f.expectCreateMachineConfigAction(mcs)
f.expectGetMachineConfigAction(mcs2)
f.expectGetMachineConfigAction(mcs2Deprecated)
f.expectGetMachineConfigAction(mcs2)
f.expectCreateMachineConfigAction(mcs2)
f.runFeature(getKeyFromFeatureGate(features, t))
})
}
}

0 comments on commit 4c77ed7

Please sign in to comment.