Add an option to skip NTP installation

Add NTPConfig to ClusterSpec. NTPConfig has the SkipInstall option.

https://github.com/kubernetes/kops/issues/9661
This commit is contained in:
Kenji Kaneda 2021-03-30 00:19:23 -07:00
parent 9775182ee4
commit baff30d66e
12 changed files with 185 additions and 0 deletions

View File

@ -1293,3 +1293,14 @@ spec:
In the case of containerd, the cgroup-driver is dependant on the cgroup driver of kubelet. To use cgroupfs, just update the
cgroupDriver of kubelet to use cgroupfs.
## NTP
The installation and the configuration of NTP can be skipped by setting `managed` to `false`.
```yaml
spec:
ntp:
managed: false
```

View File

@ -3913,6 +3913,15 @@ spec:
NonMasqueradeCIDR is the CIDR for the internal k8s network (on which
pods & services live) It cannot overlap ServiceClusterIPRange
type: string
ntp:
description: NTPConfig is the configuration for NTP.
properties:
managed:
description: Managed controls if the NTP configuration is managed
by kOps. The NTP configuration task is skipped if this is set
to false.
type: boolean
type: object
podCIDR:
description: PodCIDR is the CIDR from which we allocate IPs for pods
type: string

View File

@ -34,6 +34,11 @@ var _ fi.ModelBuilder = &NTPBuilder{}
// Build is responsible for configuring NTP
func (b *NTPBuilder) Build(c *fi.ModelBuilderContext) error {
if !b.managed() {
klog.Infof("Managed is set to false; won't install NTP")
return nil
}
switch b.Distribution {
case distributions.DistributionContainerOS:
klog.Infof("Detected ContainerOS; won't install ntp")
@ -112,3 +117,11 @@ NTP=` + host + `
Mode: s("0644"),
}
}
// managed determines if kops should manage the installation and configuration of NTP.
func (b *NTPBuilder) managed() bool {
n := b.Cluster.Spec.NTP
// Consider the NTP is managed when the NTP configuration
// is not specified (for backward compatibility).
return n == nil || n.Managed == nil || *n.Managed
}

View File

@ -14,6 +14,7 @@ go_library(
"keyset.go",
"labels.go",
"networking.go",
"ntpconfig.go",
"parse.go",
"register.go",
"sshcredential.go",

View File

@ -159,6 +159,7 @@ type ClusterSpec struct {
MasterKubelet *KubeletConfigSpec `json:"masterKubelet,omitempty"`
CloudConfig *CloudConfiguration `json:"cloudConfig,omitempty"`
ExternalDNS *ExternalDNSConfig `json:"externalDns,omitempty"`
NTP *NTPConfig `json:"ntp,omitempty"`
// NodeTerminationHandler determines the cluster autoscaler configuration.
NodeTerminationHandler *NodeTerminationHandlerConfig `json:"nodeTerminationHandler,omitempty"`

View File

@ -0,0 +1,24 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kops
// NTPConfig is the configuration for NTP.
type NTPConfig struct {
// Managed controls if the NTP configuration is managed by kOps.
// The NTP configuration task is skipped if this is set to false.
Managed *bool `json:"managed,omitempty"`
}

View File

@ -13,6 +13,7 @@ go_library(
"instancegroup.go",
"keyset.go",
"networking.go",
"ntpconfig.go",
"register.go",
"sshcredential.go",
"topology.go",

View File

@ -158,6 +158,7 @@ type ClusterSpec struct {
MasterKubelet *KubeletConfigSpec `json:"masterKubelet,omitempty"`
CloudConfig *CloudConfiguration `json:"cloudConfig,omitempty"`
ExternalDNS *ExternalDNSConfig `json:"externalDns,omitempty"`
NTP *NTPConfig `json:"ntp,omitempty"`
// NodeTerminationHandler determines the cluster autoscaler configuration.
NodeTerminationHandler *NodeTerminationHandlerConfig `json:"nodeTerminationHandler,omitempty"`

View File

@ -0,0 +1,24 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha2
// NTPConfig is the configuration for NTP.
type NTPConfig struct {
// Managed controls if the NTP configuration is managed by kOps.
// The NTP configuration task is skipped if this is set to false.
Managed *bool `json:"managed,omitempty"`
}

View File

@ -793,6 +793,16 @@ func RegisterConversions(s *runtime.Scheme) error {
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*NTPConfig)(nil), (*kops.NTPConfig)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha2_NTPConfig_To_kops_NTPConfig(a.(*NTPConfig), b.(*kops.NTPConfig), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*kops.NTPConfig)(nil), (*NTPConfig)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_kops_NTPConfig_To_v1alpha2_NTPConfig(a.(*kops.NTPConfig), b.(*NTPConfig), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*NetworkingSpec)(nil), (*kops.NetworkingSpec)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha2_NetworkingSpec_To_kops_NetworkingSpec(a.(*NetworkingSpec), b.(*kops.NetworkingSpec), scope)
}); err != nil {
@ -2322,6 +2332,15 @@ func autoConvert_v1alpha2_ClusterSpec_To_kops_ClusterSpec(in *ClusterSpec, out *
} else {
out.ExternalDNS = nil
}
if in.NTP != nil {
in, out := &in.NTP, &out.NTP
*out = new(kops.NTPConfig)
if err := Convert_v1alpha2_NTPConfig_To_kops_NTPConfig(*in, *out, s); err != nil {
return err
}
} else {
out.NTP = nil
}
if in.NodeTerminationHandler != nil {
in, out := &in.NodeTerminationHandler, &out.NodeTerminationHandler
*out = new(kops.NodeTerminationHandlerConfig)
@ -2690,6 +2709,15 @@ func autoConvert_kops_ClusterSpec_To_v1alpha2_ClusterSpec(in *kops.ClusterSpec,
} else {
out.ExternalDNS = nil
}
if in.NTP != nil {
in, out := &in.NTP, &out.NTP
*out = new(NTPConfig)
if err := Convert_kops_NTPConfig_To_v1alpha2_NTPConfig(*in, *out, s); err != nil {
return err
}
} else {
out.NTP = nil
}
if in.NodeTerminationHandler != nil {
in, out := &in.NodeTerminationHandler, &out.NodeTerminationHandler
*out = new(NodeTerminationHandlerConfig)
@ -5290,6 +5318,26 @@ func Convert_kops_MixedInstancesPolicySpec_To_v1alpha2_MixedInstancesPolicySpec(
return autoConvert_kops_MixedInstancesPolicySpec_To_v1alpha2_MixedInstancesPolicySpec(in, out, s)
}
func autoConvert_v1alpha2_NTPConfig_To_kops_NTPConfig(in *NTPConfig, out *kops.NTPConfig, s conversion.Scope) error {
out.Managed = in.Managed
return nil
}
// Convert_v1alpha2_NTPConfig_To_kops_NTPConfig is an autogenerated conversion function.
func Convert_v1alpha2_NTPConfig_To_kops_NTPConfig(in *NTPConfig, out *kops.NTPConfig, s conversion.Scope) error {
return autoConvert_v1alpha2_NTPConfig_To_kops_NTPConfig(in, out, s)
}
func autoConvert_kops_NTPConfig_To_v1alpha2_NTPConfig(in *kops.NTPConfig, out *NTPConfig, s conversion.Scope) error {
out.Managed = in.Managed
return nil
}
// Convert_kops_NTPConfig_To_v1alpha2_NTPConfig is an autogenerated conversion function.
func Convert_kops_NTPConfig_To_v1alpha2_NTPConfig(in *kops.NTPConfig, out *NTPConfig, s conversion.Scope) error {
return autoConvert_kops_NTPConfig_To_v1alpha2_NTPConfig(in, out, s)
}
func autoConvert_v1alpha2_NetworkingSpec_To_kops_NetworkingSpec(in *NetworkingSpec, out *kops.NetworkingSpec, s conversion.Scope) error {
if in.Classic != nil {
in, out := &in.Classic, &out.Classic

View File

@ -964,6 +964,11 @@ func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) {
*out = new(ExternalDNSConfig)
(*in).DeepCopyInto(*out)
}
if in.NTP != nil {
in, out := &in.NTP, &out.NTP
*out = new(NTPConfig)
(*in).DeepCopyInto(*out)
}
if in.NodeTerminationHandler != nil {
in, out := &in.NodeTerminationHandler, &out.NodeTerminationHandler
*out = new(NodeTerminationHandlerConfig)
@ -3646,6 +3651,27 @@ func (in *MixedInstancesPolicySpec) DeepCopy() *MixedInstancesPolicySpec {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NTPConfig) DeepCopyInto(out *NTPConfig) {
*out = *in
if in.Managed != nil {
in, out := &in.Managed, &out.Managed
*out = new(bool)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NTPConfig.
func (in *NTPConfig) DeepCopy() *NTPConfig {
if in == nil {
return nil
}
out := new(NTPConfig)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NetworkingSpec) DeepCopyInto(out *NetworkingSpec) {
*out = *in

View File

@ -1064,6 +1064,11 @@ func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) {
*out = new(ExternalDNSConfig)
(*in).DeepCopyInto(*out)
}
if in.NTP != nil {
in, out := &in.NTP, &out.NTP
*out = new(NTPConfig)
(*in).DeepCopyInto(*out)
}
if in.NodeTerminationHandler != nil {
in, out := &in.NodeTerminationHandler, &out.NodeTerminationHandler
*out = new(NodeTerminationHandlerConfig)
@ -3844,6 +3849,27 @@ func (in *MixedInstancesPolicySpec) DeepCopy() *MixedInstancesPolicySpec {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NTPConfig) DeepCopyInto(out *NTPConfig) {
*out = *in
if in.Managed != nil {
in, out := &in.Managed, &out.Managed
*out = new(bool)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NTPConfig.
func (in *NTPConfig) DeepCopy() *NTPConfig {
if in == nil {
return nil
}
out := new(NTPConfig)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NetworkingSpec) DeepCopyInto(out *NetworkingSpec) {
*out = *in