@@ -67,9 +67,9 @@ func (nodeStrategy) AllowCreateOnUpdate() bool {
67
67
func (nodeStrategy ) PrepareForCreate (ctx context.Context , obj runtime.Object ) {
68
68
node := obj .(* api.Node )
69
69
// Nodes allow *all* fields, including status, to be set on create.
70
-
71
70
if ! utilfeature .DefaultFeatureGate .Enabled (features .DynamicKubeletConfig ) {
72
71
node .Spec .ConfigSource = nil
72
+ node .Status .Config = nil
73
73
}
74
74
}
75
75
@@ -79,12 +79,22 @@ func (nodeStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Objec
79
79
oldNode := old .(* api.Node )
80
80
newNode .Status = oldNode .Status
81
81
82
- if ! utilfeature .DefaultFeatureGate .Enabled (features .DynamicKubeletConfig ) {
82
+ if ! utilfeature .DefaultFeatureGate .Enabled (features .DynamicKubeletConfig ) && ! nodeConfigSourceInUse ( oldNode ) {
83
83
newNode .Spec .ConfigSource = nil
84
- oldNode .Spec .ConfigSource = nil
85
84
}
86
85
}
87
86
87
+ // nodeConfigSourceInUse returns true if node's Spec ConfigSource is set(used)
88
+ func nodeConfigSourceInUse (node * api.Node ) bool {
89
+ if node == nil {
90
+ return false
91
+ }
92
+ if node .Spec .ConfigSource != nil {
93
+ return true
94
+ }
95
+ return false
96
+ }
97
+
88
98
// Validate validates a new node.
89
99
func (nodeStrategy ) Validate (ctx context.Context , obj runtime.Object ) field.ErrorList {
90
100
node := obj .(* api.Node )
@@ -127,26 +137,27 @@ type nodeStatusStrategy struct {
127
137
128
138
var StatusStrategy = nodeStatusStrategy {Strategy }
129
139
130
- func (nodeStatusStrategy ) PrepareForCreate (ctx context.Context , obj runtime.Object ) {
131
- node := obj .(* api.Node )
132
- // Nodes allow *all* fields, including status, to be set on create.
133
-
134
- if ! utilfeature .DefaultFeatureGate .Enabled (features .DynamicKubeletConfig ) {
135
- node .Status .Config = nil
136
- }
137
- }
138
-
139
140
func (nodeStatusStrategy ) PrepareForUpdate (ctx context.Context , obj , old runtime.Object ) {
140
141
newNode := obj .(* api.Node )
141
142
oldNode := old .(* api.Node )
142
143
newNode .Spec = oldNode .Spec
143
144
144
- if ! utilfeature .DefaultFeatureGate .Enabled (features .DynamicKubeletConfig ) {
145
+ if ! utilfeature .DefaultFeatureGate .Enabled (features .DynamicKubeletConfig ) && ! nodeStatusConfigInUse ( oldNode ) {
145
146
newNode .Status .Config = nil
146
- oldNode .Status .Config = nil
147
147
}
148
148
}
149
149
150
+ // nodeStatusConfigInUse returns true if node's Status Config is set(used)
151
+ func nodeStatusConfigInUse (node * api.Node ) bool {
152
+ if node == nil {
153
+ return false
154
+ }
155
+ if node .Status .Config != nil {
156
+ return true
157
+ }
158
+ return false
159
+ }
160
+
150
161
func (nodeStatusStrategy ) ValidateUpdate (ctx context.Context , obj , old runtime.Object ) field.ErrorList {
151
162
return validation .ValidateNodeUpdate (obj .(* api.Node ), old .(* api.Node ))
152
163
}
0 commit comments