Skip to content

Commit e61b76f

Browse files
committed
node config_source
Signed-off-by: Serguei Bezverkhi <[email protected]>
1 parent 5ac194e commit e61b76f

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

pkg/apis/core/validation/validation.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,16 +4147,6 @@ func ValidateNode(node *core.Node) field.ErrorList {
41474147
// That said, if specified, we need to ensure they are valid.
41484148
allErrs = append(allErrs, ValidateNodeResources(node)...)
41494149

4150-
// Only allow Spec.ConfigSource and Status.Config to be set if the DynamicKubeletConfig feature gate is enabled
4151-
if !utilfeature.DefaultFeatureGate.Enabled(features.DynamicKubeletConfig) {
4152-
if node.Spec.ConfigSource != nil {
4153-
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "configSource"), "configSource may only be set if the DynamicKubeletConfig feature gate is enabled)"))
4154-
}
4155-
if node.Status.Config != nil {
4156-
allErrs = append(allErrs, field.Forbidden(field.NewPath("status", "config"), "config may only be set if the DynamicKubeletConfig feature gate is enabled)"))
4157-
}
4158-
}
4159-
41604150
if len(node.Spec.PodCIDR) != 0 {
41614151
_, err := ValidateCIDR(node.Spec.PodCIDR)
41624152
if err != nil {
@@ -4239,17 +4229,14 @@ func ValidateNodeUpdate(node, oldNode *core.Node) field.ErrorList {
42394229
}
42404230
}
42414231

4242-
// Allow and validate updates to Node.Spec.ConfigSource and Node.Status.Config if DynamicKubeletConfig feature gate is enabled
4243-
if utilfeature.DefaultFeatureGate.Enabled(features.DynamicKubeletConfig) {
4244-
if node.Spec.ConfigSource != nil {
4245-
allErrs = append(allErrs, validateNodeConfigSourceSpec(node.Spec.ConfigSource, field.NewPath("spec", "configSource"))...)
4246-
}
4247-
oldNode.Spec.ConfigSource = node.Spec.ConfigSource
4248-
if node.Status.Config != nil {
4249-
allErrs = append(allErrs, validateNodeConfigStatus(node.Status.Config, field.NewPath("status", "config"))...)
4250-
}
4251-
oldNode.Status.Config = node.Status.Config
4232+
if node.Spec.ConfigSource != nil {
4233+
allErrs = append(allErrs, validateNodeConfigSourceSpec(node.Spec.ConfigSource, field.NewPath("spec", "configSource"))...)
4234+
}
4235+
oldNode.Spec.ConfigSource = node.Spec.ConfigSource
4236+
if node.Status.Config != nil {
4237+
allErrs = append(allErrs, validateNodeConfigStatus(node.Status.Config, field.NewPath("status", "config"))...)
42524238
}
4239+
oldNode.Status.Config = node.Status.Config
42534240

42544241
// TODO: move reset function to its own location
42554242
// Ignore metadata changes now that they have been tested

pkg/registry/core/node/strategy.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ func (nodeStrategy) AllowCreateOnUpdate() bool {
6767
func (nodeStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
6868
node := obj.(*api.Node)
6969
// Nodes allow *all* fields, including status, to be set on create.
70-
7170
if !utilfeature.DefaultFeatureGate.Enabled(features.DynamicKubeletConfig) {
7271
node.Spec.ConfigSource = nil
72+
node.Status.Config = nil
7373
}
7474
}
7575

@@ -79,12 +79,22 @@ func (nodeStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Objec
7979
oldNode := old.(*api.Node)
8080
newNode.Status = oldNode.Status
8181

82-
if !utilfeature.DefaultFeatureGate.Enabled(features.DynamicKubeletConfig) {
82+
if !utilfeature.DefaultFeatureGate.Enabled(features.DynamicKubeletConfig) && !nodeConfigSourceInUse(oldNode) {
8383
newNode.Spec.ConfigSource = nil
84-
oldNode.Spec.ConfigSource = nil
8584
}
8685
}
8786

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+
8898
// Validate validates a new node.
8999
func (nodeStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
90100
node := obj.(*api.Node)
@@ -127,26 +137,27 @@ type nodeStatusStrategy struct {
127137

128138
var StatusStrategy = nodeStatusStrategy{Strategy}
129139

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-
139140
func (nodeStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
140141
newNode := obj.(*api.Node)
141142
oldNode := old.(*api.Node)
142143
newNode.Spec = oldNode.Spec
143144

144-
if !utilfeature.DefaultFeatureGate.Enabled(features.DynamicKubeletConfig) {
145+
if !utilfeature.DefaultFeatureGate.Enabled(features.DynamicKubeletConfig) && !nodeStatusConfigInUse(oldNode) {
145146
newNode.Status.Config = nil
146-
oldNode.Status.Config = nil
147147
}
148148
}
149149

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+
150161
func (nodeStatusStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
151162
return validation.ValidateNodeUpdate(obj.(*api.Node), old.(*api.Node))
152163
}

0 commit comments

Comments
 (0)