mirror of https://github.com/kubernetes/kops.git
Move NTP and misc package initialization to code
Paring down the nodeup portion of gobindata
This commit is contained in:
parent
e187adb0e7
commit
10a7f9afb0
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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})
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue