Skip to content

Commit

Permalink
Apply mc-name-suffix annotation to kubeletconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
SrinivasAtmakuri committed Jan 16, 2024
1 parent aee18fe commit ae87b31
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type Reconciler struct {
const (
ControllerName = "AutoSizedNodes"
configName = "dynamic-node"

// machineconfiguration annotation added on the kubelet CRD - dynamic-node
mcAnnotationName = "machineconfiguration.openshift.io/mc-name-suffix"
mcAnnotationValue = ""
)

func NewReconciler(log *logrus.Entry, client client.Client) *Reconciler {
Expand Down Expand Up @@ -90,7 +94,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
return ctrl.Result{}, fmt.Errorf("could not fetch KubeletConfig: %w", err)
}

// If already exists, update the spec
// If already exists, update the spec and annotations
if config.Annotations == nil {
config.Annotations = defaultConfig.Annotations
}
if val, ok := config.Annotations[mcAnnotationName]; !ok || val != mcAnnotationValue {
config.Annotations[mcAnnotationName] = mcAnnotationValue
}

config.Spec = defaultConfig.Spec
err = r.client.Update(ctx, &config)
if err != nil {
Expand Down Expand Up @@ -120,7 +131,8 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
func makeConfig() mcv1.KubeletConfig {
return mcv1.KubeletConfig{
ObjectMeta: metav1.ObjectMeta{
Name: configName,
Name: configName,
Annotations: map[string]string{mcAnnotationName: mcAnnotationValue},
},
Spec: mcv1.KubeletConfigSpec{
AutoSizingReserved: to.BoolPtr(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ func TestAutosizednodesReconciler(t *testing.T) {
aro(true),
&mcv1.KubeletConfig{
ObjectMeta: metav1.ObjectMeta{
Name: configName,
Name: configName,
Annotations: map[string]string{"machineconfiguration.openshift.io/mc-name-suffix": "2"},
},
Spec: mcv1.KubeletConfigSpec{
AutoSizingReserved: to.BoolPtr(false),
Expand Down Expand Up @@ -121,6 +122,9 @@ func TestAutosizednodesReconciler(t *testing.T) {
if !reflect.DeepEqual(test.wantConfig.Spec, c.Spec) {
t.Error(cmp.Diff(test.wantConfig.Spec, c.Spec))
}
if !reflect.DeepEqual(test.wantConfig.Annotations, c.Annotations) {
t.Error(cmp.Diff(test.wantConfig.Annotations, c.Annotations))
}

if result != (ctrl.Result{}) {
t.Error("reconcile returned an unexpected result")
Expand Down
4 changes: 4 additions & 0 deletions pkg/operator/controllers/workaround/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const (
workerMachineConfigPoolName = "worker"
memReserved = "2000Mi"

// machineconfiguration annotation added on the kubelet CRD - aro-limits
mcAnnotationName = "machineconfiguration.openshift.io/mc-name-suffix"
mcAnnotationValue = ""

// ifreload workaround
kubeNamespace = "openshift-azure-ifreload"
)
4 changes: 4 additions & 0 deletions pkg/operator/controllers/workaround/systemreserved.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func (sr *systemreserved) Ensure(ctx context.Context) error {
kc.Labels = make(map[string]string)
}
kc.Labels[labelName] = labelValue
if kc.Annotations == nil {
kc.Annotations = make(map[string]string)
}
kc.Annotations[mcAnnotationName] = mcAnnotationValue

b, err := json.Marshal(map[string]interface{}{
"systemReserved": map[string]interface{}{
Expand Down
3 changes: 3 additions & 0 deletions pkg/operator/controllers/workaround/systemreserved_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func TestSystemreservedEnsure(t *testing.T) {
Labels: map[string]string{
"aro.openshift.io/limits": "",
},
Annotations: map[string]string{
"machineconfiguration.openshift.io/mc-name-suffix": "",
},
ResourceVersion: resourceVersion,
},
Spec: mcv1.KubeletConfigSpec{
Expand Down

0 comments on commit ae87b31

Please sign in to comment.