Skip to content

Commit

Permalink
Merge pull request #7772 from akshay196/add-support-imagepullpolicy
Browse files Browse the repository at this point in the history
✨ Add NodeRegistrationOptions.ImagePullPolicy Support
  • Loading branch information
k8s-ci-robot authored Jan 30, 2023
2 parents be6bdef + 4ca79ad commit 1b61819
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 20 deletions.
28 changes: 28 additions & 0 deletions bootstrap/kubeadm/api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ func (src *KubeadmConfig) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.JoinConfiguration.SkipPhases = restored.Spec.JoinConfiguration.SkipPhases
}

if restored.Spec.JoinConfiguration != nil && restored.Spec.JoinConfiguration.NodeRegistration.ImagePullPolicy != "" {
if dst.Spec.JoinConfiguration == nil {
dst.Spec.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
}
dst.Spec.JoinConfiguration.NodeRegistration.ImagePullPolicy = restored.Spec.JoinConfiguration.NodeRegistration.ImagePullPolicy
}

if restored.Spec.InitConfiguration != nil && restored.Spec.InitConfiguration.NodeRegistration.ImagePullPolicy != "" {
if dst.Spec.InitConfiguration == nil {
dst.Spec.InitConfiguration = &bootstrapv1.InitConfiguration{}
}
dst.Spec.InitConfiguration.NodeRegistration.ImagePullPolicy = restored.Spec.InitConfiguration.NodeRegistration.ImagePullPolicy
}

return nil
}

Expand Down Expand Up @@ -163,6 +177,20 @@ func (src *KubeadmConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Template.Spec.JoinConfiguration.SkipPhases = restored.Spec.Template.Spec.JoinConfiguration.SkipPhases
}

if restored.Spec.Template.Spec.JoinConfiguration != nil && restored.Spec.Template.Spec.JoinConfiguration.NodeRegistration.ImagePullPolicy != "" {
if dst.Spec.Template.Spec.JoinConfiguration == nil {
dst.Spec.Template.Spec.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
}
dst.Spec.Template.Spec.JoinConfiguration.NodeRegistration.ImagePullPolicy = restored.Spec.Template.Spec.JoinConfiguration.NodeRegistration.ImagePullPolicy
}

if restored.Spec.Template.Spec.InitConfiguration != nil && restored.Spec.Template.Spec.InitConfiguration.NodeRegistration.ImagePullPolicy != "" {
if dst.Spec.Template.Spec.InitConfiguration == nil {
dst.Spec.Template.Spec.InitConfiguration = &bootstrapv1.InitConfiguration{}
}
dst.Spec.Template.Spec.InitConfiguration.NodeRegistration.ImagePullPolicy = restored.Spec.Template.Spec.InitConfiguration.NodeRegistration.ImagePullPolicy
}

return nil
}

Expand Down
34 changes: 34 additions & 0 deletions bootstrap/kubeadm/api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ func (src *KubeadmConfig) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.JoinConfiguration.SkipPhases = restored.Spec.JoinConfiguration.SkipPhases
}

if restored.Spec.JoinConfiguration != nil && restored.Spec.JoinConfiguration.NodeRegistration.ImagePullPolicy != "" {
if dst.Spec.JoinConfiguration == nil {
dst.Spec.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
}
dst.Spec.JoinConfiguration.NodeRegistration.ImagePullPolicy = restored.Spec.JoinConfiguration.NodeRegistration.ImagePullPolicy
}

if restored.Spec.InitConfiguration != nil && restored.Spec.InitConfiguration.NodeRegistration.ImagePullPolicy != "" {
if dst.Spec.InitConfiguration == nil {
dst.Spec.InitConfiguration = &bootstrapv1.InitConfiguration{}
}
dst.Spec.InitConfiguration.NodeRegistration.ImagePullPolicy = restored.Spec.InitConfiguration.NodeRegistration.ImagePullPolicy
}

return nil
}

Expand Down Expand Up @@ -129,6 +143,20 @@ func (src *KubeadmConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Template.Spec.JoinConfiguration.SkipPhases = restored.Spec.Template.Spec.JoinConfiguration.SkipPhases
}

if restored.Spec.Template.Spec.JoinConfiguration != nil && restored.Spec.Template.Spec.JoinConfiguration.NodeRegistration.ImagePullPolicy != "" {
if dst.Spec.Template.Spec.JoinConfiguration == nil {
dst.Spec.Template.Spec.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
}
dst.Spec.Template.Spec.JoinConfiguration.NodeRegistration.ImagePullPolicy = restored.Spec.Template.Spec.JoinConfiguration.NodeRegistration.ImagePullPolicy
}

if restored.Spec.Template.Spec.InitConfiguration != nil && restored.Spec.Template.Spec.InitConfiguration.NodeRegistration.ImagePullPolicy != "" {
if dst.Spec.Template.Spec.InitConfiguration == nil {
dst.Spec.Template.Spec.InitConfiguration = &bootstrapv1.InitConfiguration{}
}
dst.Spec.Template.Spec.InitConfiguration.NodeRegistration.ImagePullPolicy = restored.Spec.Template.Spec.InitConfiguration.NodeRegistration.ImagePullPolicy
}

return nil
}

Expand Down Expand Up @@ -179,3 +207,9 @@ func Convert_v1beta1_User_To_v1alpha4_User(in *bootstrapv1.User, out *User, s ap
// User.PasswdFrom does not exist in kubeadm v1alpha4 API.
return autoConvert_v1beta1_User_To_v1alpha4_User(in, out, s)
}

func Convert_v1beta1_NodeRegistrationOptions_To_v1alpha4_NodeRegistrationOptions(in *bootstrapv1.NodeRegistrationOptions, out *NodeRegistrationOptions, s apiconversion.Scope) error {
// NodeRegistrationOptions.ImagePullPolicy does not exit in
// kubeadm v1alpha4 API.
return autoConvert_v1beta1_NodeRegistrationOptions_To_v1alpha4_NodeRegistrationOptions(in, out, s)
}
16 changes: 6 additions & 10 deletions bootstrap/kubeadm/api/v1alpha4/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions bootstrap/kubeadm/api/v1beta1/kubeadm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ type NodeRegistrationOptions struct {
// IgnorePreflightErrors provides a slice of pre-flight errors to be ignored when the current node is registered.
// +optional
IgnorePreflightErrors []string `json:"ignorePreflightErrors,omitempty"`

// ImagePullPolicy specifies the policy for image pulling
// during kubeadm "init" and "join" operations. The value of
// this field must be one of "Always", "IfNotPresent" or
// "Never". Defaults to "IfNotPresent". This can be used only
// with Kubernetes version equal to 1.22 and later.
// +kubebuilder:validation:Enum=Always;IfNotPresent;Never
// +kubebuilder:default=IfNotPresent
// +optional
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
}

// MarshalJSON marshals NodeRegistrationOptions in a way that an empty slice in Taints is preserved.
Expand All @@ -271,12 +281,14 @@ func (n *NodeRegistrationOptions) MarshalJSON() ([]byte, error) {
Taints []corev1.Taint `json:"taints"`
KubeletExtraArgs map[string]string `json:"kubeletExtraArgs,omitempty"`
IgnorePreflightErrors []string `json:"ignorePreflightErrors,omitempty"`
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
}{
Name: n.Name,
CRISocket: n.CRISocket,
Taints: n.Taints,
KubeletExtraArgs: n.KubeletExtraArgs,
IgnorePreflightErrors: n.IgnorePreflightErrors,
ImagePullPolicy: n.ImagePullPolicy,
})
}

Expand All @@ -287,12 +299,14 @@ func (n *NodeRegistrationOptions) MarshalJSON() ([]byte, error) {
Taints []corev1.Taint `json:"taints,omitempty"`
KubeletExtraArgs map[string]string `json:"kubeletExtraArgs,omitempty"`
IgnorePreflightErrors []string `json:"ignorePreflightErrors,omitempty"`
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
}{
Name: n.Name,
CRISocket: n.CRISocket,
Taints: n.Taints,
KubeletExtraArgs: n.KubeletExtraArgs,
IgnorePreflightErrors: n.IgnorePreflightErrors,
ImagePullPolicy: n.ImagePullPolicy,
})
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions bootstrap/kubeadm/types/upstreamv1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func kubeadmNodeRegistrationOptionsFuzzer(obj *bootstrapv1.NodeRegistrationOptio
// NodeRegistrationOptions.IgnorePreflightErrors does not exist in kubeadm v1beta1 API, so setting it to nil in order to avoid
// v1alpha4 --> v1beta1 -> v1alpha4 round trip errors.
obj.IgnorePreflightErrors = nil

// NodeRegistrationOptions.ImagePullPolicy does not exist in
// kubeadm v1beta1 API, so setting it to empty in order to
// avoid round trip errors.
obj.ImagePullPolicy = ""
}

func kubeadmInitConfigurationFuzzer(obj *bootstrapv1.InitConfiguration, c fuzz.Continue) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions bootstrap/kubeadm/types/upstreamv1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ func Convert_v1beta1_JoinConfiguration_To_upstreamv1beta2_JoinConfiguration(in *
// JoinConfiguration.Patches does not exist in kubeadm v1beta2 API
return autoConvert_v1beta1_JoinConfiguration_To_upstreamv1beta2_JoinConfiguration(in, out, s)
}

func Convert_v1beta1_NodeRegistrationOptions_To_upstreamv1beta2_NodeRegistrationOptions(in *bootstrapv1.NodeRegistrationOptions, out *NodeRegistrationOptions, s apimachineryconversion.Scope) error {
// NodeRegistrationOptions.ImagePullPolicy does not exit in
// kubeadm v1beta2 API.
return autoConvert_v1beta1_NodeRegistrationOptions_To_upstreamv1beta2_NodeRegistrationOptions(in, out, s)
}
10 changes: 10 additions & 0 deletions bootstrap/kubeadm/types/upstreamv1beta2/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
clusterConfigurationFuzzer,
kubeadmInitConfigurationFuzzer,
kubeadmJoinConfigurationFuzzer,
kubeadmNodeRegistrationOptionsFuzzer,
}
}

Expand Down Expand Up @@ -120,3 +121,12 @@ func kubeadmJoinConfigurationFuzzer(obj *bootstrapv1.JoinConfiguration, c fuzz.C
// v1beta1 --> upstream v1beta2 -> v1beta1 round trip errors.
obj.SkipPhases = nil
}

func kubeadmNodeRegistrationOptionsFuzzer(obj *bootstrapv1.NodeRegistrationOptions, c fuzz.Continue) {
c.FuzzNoCustom(obj)

// NodeRegistrationOptions.ImagePullPolicy does not exist in
// kubeadm v1beta2 API, so setting it to empty in order to
// avoid round trip errors.
obj.ImagePullPolicy = ""
}
16 changes: 6 additions & 10 deletions bootstrap/kubeadm/types/upstreamv1beta2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions bootstrap/kubeadm/types/upstreamv1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ type NodeRegistrationOptions struct {
// IgnorePreflightErrors provides a slice of pre-flight errors to be ignored when the current node is registered.
// +optional
IgnorePreflightErrors []string `json:"ignorePreflightErrors,omitempty"`

// ImagePullPolicy specifies the policy for image pulling
// during kubeadm "init" and "join" operations. The value of
// this field must be one of "Always", "IfNotPresent" or
// "Never". Defaults to "IfNotPresent".
// +optional
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
}

// Networking contains elements describing cluster's networking configuration.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1b61819

Please sign in to comment.