From baff30d66ebf2317ba57e0f9bf41d963890d25f1 Mon Sep 17 00:00:00 2001 From: Kenji Kaneda Date: Tue, 30 Mar 2021 00:19:23 -0700 Subject: [PATCH] Add an option to skip NTP installation Add NTPConfig to ClusterSpec. NTPConfig has the SkipInstall option. https://github.com/kubernetes/kops/issues/9661 --- docs/cluster_spec.md | 11 +++++ k8s/crds/kops.k8s.io_clusters.yaml | 9 ++++ nodeup/pkg/model/ntp.go | 13 +++++ pkg/apis/kops/BUILD.bazel | 1 + pkg/apis/kops/cluster.go | 1 + pkg/apis/kops/ntpconfig.go | 24 ++++++++++ pkg/apis/kops/v1alpha2/BUILD.bazel | 1 + pkg/apis/kops/v1alpha2/cluster.go | 1 + pkg/apis/kops/v1alpha2/ntpconfig.go | 24 ++++++++++ .../kops/v1alpha2/zz_generated.conversion.go | 48 +++++++++++++++++++ .../kops/v1alpha2/zz_generated.deepcopy.go | 26 ++++++++++ pkg/apis/kops/zz_generated.deepcopy.go | 26 ++++++++++ 12 files changed, 185 insertions(+) create mode 100644 pkg/apis/kops/ntpconfig.go create mode 100644 pkg/apis/kops/v1alpha2/ntpconfig.go diff --git a/docs/cluster_spec.md b/docs/cluster_spec.md index a8471e1b09..8fe78c4e30 100644 --- a/docs/cluster_spec.md +++ b/docs/cluster_spec.md @@ -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 +``` + diff --git a/k8s/crds/kops.k8s.io_clusters.yaml b/k8s/crds/kops.k8s.io_clusters.yaml index bf6c6d8fc6..bf49039a71 100644 --- a/k8s/crds/kops.k8s.io_clusters.yaml +++ b/k8s/crds/kops.k8s.io_clusters.yaml @@ -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 diff --git a/nodeup/pkg/model/ntp.go b/nodeup/pkg/model/ntp.go index df773f685c..7a0f2ecd34 100644 --- a/nodeup/pkg/model/ntp.go +++ b/nodeup/pkg/model/ntp.go @@ -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 +} diff --git a/pkg/apis/kops/BUILD.bazel b/pkg/apis/kops/BUILD.bazel index 50de428036..7e07d37a43 100644 --- a/pkg/apis/kops/BUILD.bazel +++ b/pkg/apis/kops/BUILD.bazel @@ -14,6 +14,7 @@ go_library( "keyset.go", "labels.go", "networking.go", + "ntpconfig.go", "parse.go", "register.go", "sshcredential.go", diff --git a/pkg/apis/kops/cluster.go b/pkg/apis/kops/cluster.go index bf686c84c3..06adc2cb7a 100644 --- a/pkg/apis/kops/cluster.go +++ b/pkg/apis/kops/cluster.go @@ -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"` diff --git a/pkg/apis/kops/ntpconfig.go b/pkg/apis/kops/ntpconfig.go new file mode 100644 index 0000000000..59e91cdc6d --- /dev/null +++ b/pkg/apis/kops/ntpconfig.go @@ -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"` +} diff --git a/pkg/apis/kops/v1alpha2/BUILD.bazel b/pkg/apis/kops/v1alpha2/BUILD.bazel index 201bf8adad..01f635534f 100644 --- a/pkg/apis/kops/v1alpha2/BUILD.bazel +++ b/pkg/apis/kops/v1alpha2/BUILD.bazel @@ -13,6 +13,7 @@ go_library( "instancegroup.go", "keyset.go", "networking.go", + "ntpconfig.go", "register.go", "sshcredential.go", "topology.go", diff --git a/pkg/apis/kops/v1alpha2/cluster.go b/pkg/apis/kops/v1alpha2/cluster.go index 10b1020714..dd5c2098ed 100644 --- a/pkg/apis/kops/v1alpha2/cluster.go +++ b/pkg/apis/kops/v1alpha2/cluster.go @@ -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"` diff --git a/pkg/apis/kops/v1alpha2/ntpconfig.go b/pkg/apis/kops/v1alpha2/ntpconfig.go new file mode 100644 index 0000000000..5b69f552c4 --- /dev/null +++ b/pkg/apis/kops/v1alpha2/ntpconfig.go @@ -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"` +} diff --git a/pkg/apis/kops/v1alpha2/zz_generated.conversion.go b/pkg/apis/kops/v1alpha2/zz_generated.conversion.go index 54cbd13814..fe2ac20757 100644 --- a/pkg/apis/kops/v1alpha2/zz_generated.conversion.go +++ b/pkg/apis/kops/v1alpha2/zz_generated.conversion.go @@ -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 diff --git a/pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go index ddaeeddb72..6a223add81 100644 --- a/pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go @@ -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 diff --git a/pkg/apis/kops/zz_generated.deepcopy.go b/pkg/apis/kops/zz_generated.deepcopy.go index bed34aa3b4..4650d4da49 100644 --- a/pkg/apis/kops/zz_generated.deepcopy.go +++ b/pkg/apis/kops/zz_generated.deepcopy.go @@ -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