diff --git a/nodeup/pkg/distros/distribution.go b/nodeup/pkg/distros/distribution.go index eebac5e3a6..0c65ed2eaf 100644 --- a/nodeup/pkg/distros/distribution.go +++ b/nodeup/pkg/distros/distribution.go @@ -78,7 +78,25 @@ func (d Distribution) BuildTags() []string { func (d Distribution) IsDebianFamily() bool { switch d { - case DistributionJessie, DistributionXenial, DistributionBionic, DistributionDebian9, DistributionDebian10: + case DistributionJessie, DistributionDebian9, DistributionDebian10: + return true + case DistributionXenial, DistributionBionic: + return true + case DistributionCentos7, DistributionRhel7: + return false + case DistributionCoreOS, DistributionContainerOS: + return false + default: + klog.Fatalf("unknown distribution: %s", d) + return false + } +} + +func (d Distribution) IsUbuntu() bool { + switch d { + case DistributionJessie, DistributionDebian9, DistributionDebian10: + return false + case DistributionXenial, DistributionBionic: return true case DistributionCentos7, DistributionRhel7: return false diff --git a/nodeup/pkg/model/BUILD.bazel b/nodeup/pkg/model/BUILD.bazel index 99e8088a0a..1bd79a1238 100644 --- a/nodeup/pkg/model/BUILD.bazel +++ b/nodeup/pkg/model/BUILD.bazel @@ -24,8 +24,10 @@ go_library( "kubelet.go", "logrotate.go", "manifests.go", + "miscutils.go", "network.go", "node_authorizer.go", + "ntp.go", "packages.go", "protokube.go", "secrets.go", diff --git a/nodeup/pkg/model/miscutils.go b/nodeup/pkg/model/miscutils.go new file mode 100644 index 0000000000..1a1bdeb8ca --- /dev/null +++ b/nodeup/pkg/model/miscutils.go @@ -0,0 +1,74 @@ +/* +Copyright 2018 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 model + +import ( + "k8s.io/klog" + "k8s.io/kops/nodeup/pkg/distros" + "k8s.io/kops/upup/pkg/fi" + "k8s.io/kops/upup/pkg/fi/nodeup/nodetasks" +) + +// MiscUtilsBuilder ensures that some system packages that are +// required for kubernetes are installed (e.g. socat) +type MiscUtilsBuilder struct { + *NodeupModelContext +} + +var _ fi.ModelBuilder = &MiscUtilsBuilder{} + +// Build is responsible for configuring the miscellaneous packages we want installed +func (b *MiscUtilsBuilder) Build(c *fi.ModelBuilderContext) error { + switch b.Distribution { + case distros.DistributionContainerOS: + klog.V(2).Infof("Detected ContainerOS; won't install misc. utils") + return nil + case distros.DistributionCoreOS: + klog.V(2).Infof("Detected CoreOS; won't install misc. utils") + return nil + } + + // TODO: These packages have been auto-installed for a long time, and likely we don't need all of them any longer + // We could prune from auto-install at a particular k8s release (e.g. 1.13?) + + var packages []string + if b.Distribution.IsDebianFamily() { + packages = append(packages, "socat") + packages = append(packages, "curl") + packages = append(packages, "nfs-common") + packages = append(packages, "python-apt") + packages = append(packages, "apt-transport-https") + } else if b.Distribution.IsRHELFamily() { + packages = append(packages, "curl") + packages = append(packages, "python") + packages = append(packages, "git") + } else { + klog.Warningf("unknown distribution, skipping misc utils install: %v", b.Distribution) + return nil + } + + if b.Distribution.IsUbuntu() { + packages = append(packages, "netcat-traditional") + packages = append(packages, "git") + } + + for _, p := range packages { + c.AddTask(&nodetasks.Package{Name: p}) + } + + return nil +} diff --git a/nodeup/pkg/model/ntp.go b/nodeup/pkg/model/ntp.go new file mode 100644 index 0000000000..cd5512f12d --- /dev/null +++ b/nodeup/pkg/model/ntp.go @@ -0,0 +1,58 @@ +/* +Copyright 2018 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 model + +import ( + "k8s.io/klog" + "k8s.io/kops/nodeup/pkg/distros" + "k8s.io/kops/upup/pkg/fi" + "k8s.io/kops/upup/pkg/fi/nodeup/nodetasks" +) + +// NTPBuilder installs and starts NTP, to ensure accurate clock times. +// As well as general log confusion, clock-skew of more than 5 minutes +// causes AWS API calls to fail +type NTPBuilder struct { + *NodeupModelContext +} + +var _ fi.ModelBuilder = &NTPBuilder{} + +// Build is responsible for configuring NTP +func (b *NTPBuilder) Build(c *fi.ModelBuilderContext) error { + switch b.Distribution { + case distros.DistributionContainerOS: + klog.Infof("Detected ContainerOS; won't install ntp") + return nil + case distros.DistributionCoreOS: + klog.Infof("Detected CoreOS; won't install ntp") + return nil + } + + if b.Distribution.IsDebianFamily() { + c.AddTask(&nodetasks.Package{Name: "ntp"}) + c.AddTask((&nodetasks.Service{Name: "ntp"}).InitDefaults()) + } else if b.Distribution.IsRHELFamily() { + c.AddTask(&nodetasks.Package{Name: "ntp"}) + c.AddTask((&nodetasks.Service{Name: "ntpd"}).InitDefaults()) + } else { + klog.Warningf("unknown distribution, skipping ntp install: %v", b.Distribution) + return nil + } + + return nil +} diff --git a/upup/models/nodeup/ntp/_aws/_debian_family/packages/ntp b/upup/models/nodeup/ntp/_aws/_debian_family/packages/ntp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/ntp/_aws/_debian_family/services/ntp b/upup/models/nodeup/ntp/_aws/_debian_family/services/ntp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/ntp/_aws/_rhel_family/packages/ntp b/upup/models/nodeup/ntp/_aws/_rhel_family/packages/ntp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/ntp/_aws/_rhel_family/services/ntpd b/upup/models/nodeup/ntp/_aws/_rhel_family/services/ntpd deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/top/_debian_family/packages/apt-transport-https b/upup/models/nodeup/top/_debian_family/packages/apt-transport-https deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/top/_debian_family/packages/curl b/upup/models/nodeup/top/_debian_family/packages/curl deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/top/_debian_family/packages/nfs-common b/upup/models/nodeup/top/_debian_family/packages/nfs-common deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/top/_debian_family/packages/python-apt b/upup/models/nodeup/top/_debian_family/packages/python-apt deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/top/_debian_family/packages/socat b/upup/models/nodeup/top/_debian_family/packages/socat deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/top/_redhat_family/packages/curl b/upup/models/nodeup/top/_redhat_family/packages/curl deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/top/_redhat_family/packages/git b/upup/models/nodeup/top/_redhat_family/packages/git deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/top/_redhat_family/packages/python b/upup/models/nodeup/top/_redhat_family/packages/python deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/top/_ubuntu/packages/git b/upup/models/nodeup/top/_ubuntu/packages/git deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/models/nodeup/top/_ubuntu/packages/netcat-traditional b/upup/models/nodeup/top/_ubuntu/packages/netcat-traditional deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/upup/pkg/fi/nodeup/command.go b/upup/pkg/fi/nodeup/command.go index a5ebd516eb..51d1b57310 100644 --- a/upup/pkg/fi/nodeup/command.go +++ b/upup/pkg/fi/nodeup/command.go @@ -223,6 +223,8 @@ func (c *NodeUpCommand) Run(out io.Writer) error { } loader := NewLoader(c.config, c.cluster, assetStore, nodeTags) + loader.Builders = append(loader.Builders, &model.NTPBuilder{NodeupModelContext: modelContext}) + loader.Builders = append(loader.Builders, &model.MiscUtilsBuilder{NodeupModelContext: modelContext}) loader.Builders = append(loader.Builders, &model.DirectoryBuilder{NodeupModelContext: modelContext}) loader.Builders = append(loader.Builders, &model.UpdateServiceBuilder{NodeupModelContext: modelContext}) loader.Builders = append(loader.Builders, &model.VolumesBuilder{NodeupModelContext: modelContext}) diff --git a/upup/pkg/fi/nodeup/nodetasks/service.go b/upup/pkg/fi/nodeup/nodetasks/service.go index 557b6214d1..7e0662fb1f 100644 --- a/upup/pkg/fi/nodeup/nodetasks/service.go +++ b/upup/pkg/fi/nodeup/nodetasks/service.go @@ -101,7 +101,7 @@ func NewService(name string, contents string, meta string) (fi.Task, error) { return s, nil } -func (s *Service) InitDefaults() { +func (s *Service) InitDefaults() *Service { // Default some values to true: Running, SmartRestart, ManageState if s.Running == nil { s.Running = fi.Bool(true) @@ -117,6 +117,8 @@ func (s *Service) InitDefaults() { if s.Enabled == nil { s.Enabled = s.Running } + + return s } func getSystemdStatus(name string) (map[string]string, error) {