mirror of https://github.com/kubernetes/kops.git
Remove unused Tags from NodeUp
This commit is contained in:
parent
04416c38f5
commit
d75042cc85
|
@ -22,7 +22,6 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kops/nodeup/pkg/distros"
|
||||
"k8s.io/kops/pkg/systemd"
|
||||
|
@ -40,14 +39,11 @@ type Installation struct {
|
|||
}
|
||||
|
||||
func (i *Installation) Run() error {
|
||||
distribution, err := distros.FindDistribution(i.FSRoot)
|
||||
_, err := distros.FindDistribution(i.FSRoot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error determining OS distribution: %v", err)
|
||||
}
|
||||
|
||||
tags := sets.NewString()
|
||||
tags.Insert(distribution.BuildTags()...)
|
||||
|
||||
tasks := make(map[string]fi.Task)
|
||||
|
||||
buildContext := &fi.ModelBuilderContext{
|
||||
|
@ -75,7 +71,6 @@ func (i *Installation) Run() error {
|
|||
|
||||
target := &local.LocalTarget{
|
||||
CacheDir: i.CacheDir,
|
||||
Tags: tags,
|
||||
}
|
||||
|
||||
checkExisting := true
|
||||
|
|
|
@ -18,7 +18,6 @@ package distros
|
|||
|
||||
import (
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kops/upup/pkg/fi/nodeup/tags"
|
||||
)
|
||||
|
||||
type Distribution string
|
||||
|
@ -38,50 +37,6 @@ var (
|
|||
DistributionContainerOS Distribution = "containeros"
|
||||
)
|
||||
|
||||
func (d Distribution) BuildTags() []string {
|
||||
var t []string
|
||||
|
||||
switch d {
|
||||
case DistributionDebian9, DistributionDebian10:
|
||||
t = []string{} // trying to move away from tags
|
||||
case DistributionXenial:
|
||||
t = []string{"_xenial"}
|
||||
case DistributionBionic:
|
||||
t = []string{"_bionic"}
|
||||
case DistributionFocal:
|
||||
t = []string{"_focal"}
|
||||
case DistributionAmazonLinux2:
|
||||
t = []string{"_amazonlinux2"}
|
||||
case DistributionCentos7:
|
||||
t = []string{"_centos7"}
|
||||
case DistributionRhel7:
|
||||
t = []string{"_rhel7"}
|
||||
case DistributionCentos8:
|
||||
t = []string{"_centos8"}
|
||||
case DistributionRhel8:
|
||||
t = []string{"_rhel8"}
|
||||
case DistributionFlatcar:
|
||||
t = []string{"_flatcar"}
|
||||
case DistributionContainerOS:
|
||||
t = []string{"_containeros"}
|
||||
default:
|
||||
klog.Fatalf("unknown distribution: %s", d)
|
||||
return nil
|
||||
}
|
||||
|
||||
if d.IsDebianFamily() {
|
||||
t = append(t, tags.TagOSFamilyDebian)
|
||||
}
|
||||
if d.IsRHELFamily() {
|
||||
t = append(t, tags.TagOSFamilyRHEL)
|
||||
}
|
||||
if d.IsSystemd() {
|
||||
t = append(t, tags.TagSystemd)
|
||||
}
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (d Distribution) IsDebianFamily() bool {
|
||||
switch d {
|
||||
case DistributionDebian9, DistributionDebian10:
|
||||
|
|
|
@ -23,7 +23,6 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/utils"
|
||||
|
@ -32,7 +31,6 @@ import (
|
|||
type CloudInitTarget struct {
|
||||
Config *CloudConfig
|
||||
out io.Writer
|
||||
Tags sets.String
|
||||
}
|
||||
|
||||
type AddBehaviour int
|
||||
|
@ -42,11 +40,10 @@ const (
|
|||
Once
|
||||
)
|
||||
|
||||
func NewCloudInitTarget(out io.Writer, tags sets.String) *CloudInitTarget {
|
||||
func NewCloudInitTarget(out io.Writer) *CloudInitTarget {
|
||||
t := &CloudInitTarget{
|
||||
Config: &CloudConfig{},
|
||||
out: out,
|
||||
Tags: tags,
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
@ -69,11 +66,6 @@ type CloudConfigFile struct {
|
|||
Content string `json:"content,omitempty"`
|
||||
}
|
||||
|
||||
func (t *CloudInitTarget) HasTag(tag string) bool {
|
||||
_, found := t.Tags[tag]
|
||||
return found
|
||||
}
|
||||
|
||||
func (t *CloudInitTarget) ProcessDeletions() bool {
|
||||
// We don't expect any, but it would be our job to process them
|
||||
return true
|
||||
|
|
|
@ -46,7 +46,6 @@ import (
|
|||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
|
@ -163,22 +162,11 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
|
|||
return fmt.Errorf("error determining OS architecture: %v", err)
|
||||
}
|
||||
|
||||
archTags := architecture.BuildTags()
|
||||
|
||||
distribution, err := distros.FindDistribution(c.FSRoot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error determining OS distribution: %v", err)
|
||||
}
|
||||
|
||||
distroTags := distribution.BuildTags()
|
||||
|
||||
nodeTags := sets.NewString()
|
||||
nodeTags.Insert(archTags...)
|
||||
nodeTags.Insert(distroTags...)
|
||||
|
||||
klog.Infof("Arch tags: %v", archTags)
|
||||
klog.Infof("Distro tags: %v", distroTags)
|
||||
|
||||
configAssets := c.config.Assets[architecture]
|
||||
assetStore := fi.NewAssetStore(c.CacheDir)
|
||||
for _, asset := range configAssets {
|
||||
|
@ -290,14 +278,13 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
|
|||
case "direct":
|
||||
target = &local.LocalTarget{
|
||||
CacheDir: c.CacheDir,
|
||||
Tags: nodeTags,
|
||||
}
|
||||
case "dryrun":
|
||||
assetBuilder := assets.NewAssetBuilder(c.cluster, "")
|
||||
target = fi.NewDryRunTarget(assetBuilder, out)
|
||||
case "cloudinit":
|
||||
checkExisting = false
|
||||
target = cloudinit.NewCloudInitTarget(out, nodeTags)
|
||||
target = cloudinit.NewCloudInitTarget(out)
|
||||
default:
|
||||
return fmt.Errorf("unsupported target type %q", c.Target)
|
||||
}
|
||||
|
|
|
@ -19,13 +19,11 @@ package local
|
|||
import (
|
||||
"os/exec"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
)
|
||||
|
||||
type LocalTarget struct {
|
||||
CacheDir string
|
||||
Tags sets.String
|
||||
}
|
||||
|
||||
var _ fi.Target = &LocalTarget{}
|
||||
|
@ -39,11 +37,6 @@ func (t *LocalTarget) ProcessDeletions() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (t *LocalTarget) HasTag(tag string) bool {
|
||||
_, found := t.Tags[tag]
|
||||
return found
|
||||
}
|
||||
|
||||
// CombinedOutput is a helper function that executes a command, returning stdout & stderr combined
|
||||
func (t *LocalTarget) CombinedOutput(args []string) ([]byte, error) {
|
||||
c := exec.Command(args[0], args[1:]...)
|
||||
|
|
|
@ -26,11 +26,11 @@ import (
|
|||
"sync"
|
||||
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kops/nodeup/pkg/distros"
|
||||
"k8s.io/kops/pkg/apis/kops"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/nodeup/cloudinit"
|
||||
"k8s.io/kops/upup/pkg/fi/nodeup/local"
|
||||
"k8s.io/kops/upup/pkg/fi/nodeup/tags"
|
||||
"k8s.io/kops/util/pkg/hashing"
|
||||
)
|
||||
|
||||
|
@ -129,13 +129,16 @@ func (p *Package) String() string {
|
|||
}
|
||||
|
||||
func (e *Package) Find(c *fi.Context) (*Package, error) {
|
||||
target := c.Target.(*local.LocalTarget)
|
||||
d, err := distros.FindDistribution("/")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unknown or unsupported distro: %v", err)
|
||||
}
|
||||
|
||||
if target.HasTag(tags.TagOSFamilyDebian) {
|
||||
if d.IsDebianFamily() {
|
||||
return e.findDpkg(c)
|
||||
}
|
||||
|
||||
if target.HasTag(tags.TagOSFamilyRHEL) {
|
||||
if d.IsRHELFamily() {
|
||||
return e.findYum(c)
|
||||
}
|
||||
|
||||
|
@ -270,6 +273,11 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
|
|||
packageManagerLock.Lock()
|
||||
defer packageManagerLock.Unlock()
|
||||
|
||||
d, err := distros.FindDistribution("/")
|
||||
if err != nil {
|
||||
return fmt.Errorf("unknown or unsupported distro: %v", err)
|
||||
}
|
||||
|
||||
if a == nil || changes.Version != nil {
|
||||
klog.Infof("Installing package %q (dependencies: %v)", e.Name, e.Deps)
|
||||
var pkgs []string
|
||||
|
@ -283,9 +291,9 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
|
|||
|
||||
// Append file extension for local files
|
||||
var ext string
|
||||
if t.HasTag(tags.TagOSFamilyDebian) {
|
||||
if d.IsDebianFamily() {
|
||||
ext = ".deb"
|
||||
} else if t.HasTag(tags.TagOSFamilyRHEL) {
|
||||
} else if d.IsRHELFamily() {
|
||||
ext = ".rpm"
|
||||
} else {
|
||||
return fmt.Errorf("unsupported package system")
|
||||
|
@ -315,11 +323,11 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
|
|||
|
||||
var args []string
|
||||
env := os.Environ()
|
||||
if t.HasTag(tags.TagOSFamilyDebian) {
|
||||
if d.IsDebianFamily() {
|
||||
args = []string{"apt-get", "install", "--yes", "--no-install-recommends"}
|
||||
env = append(env, "DEBIAN_FRONTEND=noninteractive")
|
||||
} else if t.HasTag(tags.TagOSFamilyRHEL) {
|
||||
if t.HasTag(tags.TagOSCentOS8) || t.HasTag(tags.TagOSRHEL8) {
|
||||
} else if d.IsRHELFamily() {
|
||||
if d == distros.DistributionCentos8 || d == distros.DistributionRhel8 {
|
||||
args = []string{"/usr/bin/dnf", "install", "-y", "--setopt=install_weak_deps=False"}
|
||||
} else {
|
||||
args = []string{"/usr/bin/yum", "install", "-y"}
|
||||
|
@ -338,7 +346,7 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
|
|||
}
|
||||
} else {
|
||||
if changes.Healthy != nil {
|
||||
if t.HasTag(tags.TagOSFamilyDebian) {
|
||||
if d.IsDebianFamily() {
|
||||
args := []string{"dpkg", "--configure", "-a"}
|
||||
klog.Infof("package is not healthy; running command %s", args)
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
|
@ -348,7 +356,7 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
|
|||
}
|
||||
|
||||
changes.Healthy = nil
|
||||
} else if t.HasTag(tags.TagOSFamilyRHEL) {
|
||||
} else if d.IsRHELFamily() {
|
||||
// Not set on TagOSFamilyRHEL, we can't currently reach here anyway...
|
||||
return fmt.Errorf("package repair not supported on RHEL/CentOS")
|
||||
} else {
|
||||
|
|
|
@ -26,10 +26,10 @@ import (
|
|||
"time"
|
||||
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kops/nodeup/pkg/distros"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/nodeup/cloudinit"
|
||||
"k8s.io/kops/upup/pkg/fi/nodeup/local"
|
||||
"k8s.io/kops/upup/pkg/fi/nodeup/tags"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -126,14 +126,19 @@ func getSystemdStatus(name string) (map[string]string, error) {
|
|||
return properties, nil
|
||||
}
|
||||
|
||||
func (e *Service) systemdSystemPath(target tags.HasTags) (string, error) {
|
||||
if target.HasTag(tags.TagOSFamilyDebian) {
|
||||
func (e *Service) systemdSystemPath() (string, error) {
|
||||
d, err := distros.FindDistribution("/")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unknown or unsupported distro: %v", err)
|
||||
}
|
||||
|
||||
if d.IsDebianFamily() {
|
||||
return debianSystemdSystemPath, nil
|
||||
} else if target.HasTag(tags.TagOSFamilyRHEL) {
|
||||
} else if d.IsRHELFamily() {
|
||||
return centosSystemdSystemPath, nil
|
||||
} else if target.HasTag("_flatcar") {
|
||||
} else if d == distros.DistributionFlatcar {
|
||||
return flatcarSystemdSystemPath, nil
|
||||
} else if target.HasTag("_containeros") {
|
||||
} else if d == distros.DistributionContainerOS {
|
||||
return containerosSystemdSystemPath, nil
|
||||
} else {
|
||||
return "", fmt.Errorf("unsupported systemd system")
|
||||
|
@ -141,7 +146,7 @@ func (e *Service) systemdSystemPath(target tags.HasTags) (string, error) {
|
|||
}
|
||||
|
||||
func (e *Service) Find(c *fi.Context) (*Service, error) {
|
||||
systemdSystemPath, err := e.systemdSystemPath(c.Target.(tags.HasTags))
|
||||
systemdSystemPath, err := e.systemdSystemPath()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -239,7 +244,7 @@ func (s *Service) CheckChanges(a, e, changes *Service) error {
|
|||
}
|
||||
|
||||
func (_ *Service) RenderLocal(t *local.LocalTarget, a, e, changes *Service) error {
|
||||
systemdSystemPath, err := e.systemdSystemPath(t)
|
||||
systemdSystemPath, err := e.systemdSystemPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -355,7 +360,7 @@ func (_ *Service) RenderLocal(t *local.LocalTarget, a, e, changes *Service) erro
|
|||
}
|
||||
|
||||
func (_ *Service) RenderCloudInit(t *cloudinit.CloudInitTarget, a, e, changes *Service) error {
|
||||
systemdSystemPath, err := e.systemdSystemPath(t)
|
||||
systemdSystemPath, err := e.systemdSystemPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ import (
|
|||
"syscall"
|
||||
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kops/nodeup/pkg/distros"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/nodeup/cloudinit"
|
||||
"k8s.io/kops/upup/pkg/fi/nodeup/local"
|
||||
"k8s.io/kops/upup/pkg/fi/nodeup/tags"
|
||||
)
|
||||
|
||||
type UpdatePackages struct {
|
||||
|
@ -65,11 +65,15 @@ func (_ *UpdatePackages) RenderLocal(t *local.LocalTarget, a, e, changes *Update
|
|||
klog.Infof("SKIP_PACKAGE_UPDATE was set; skipping package update")
|
||||
return nil
|
||||
}
|
||||
d, err := distros.FindDistribution("/")
|
||||
if err != nil {
|
||||
return fmt.Errorf("unknown or unsupported distro: %v", err)
|
||||
}
|
||||
var args []string
|
||||
if t.HasTag(tags.TagOSFamilyDebian) {
|
||||
if d.IsDebianFamily() {
|
||||
args = []string{"apt-get", "update"}
|
||||
|
||||
} else if t.HasTag(tags.TagOSFamilyRHEL) {
|
||||
} else if d.IsRHELFamily() {
|
||||
// Probably not technically needed
|
||||
args = []string{"/usr/bin/yum", "check-update"}
|
||||
} else {
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["tags.go"],
|
||||
importpath = "k8s.io/kops/upup/pkg/fi/nodeup/tags",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
Copyright 2019 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 tags
|
||||
|
||||
const (
|
||||
TagOSFamilyRHEL = "_rhel_family"
|
||||
TagOSFamilyDebian = "_debian_family"
|
||||
|
||||
TagOSCentOS8 = "_centos8"
|
||||
TagOSRHEL8 = "_rhel8"
|
||||
|
||||
TagSystemd = "_systemd"
|
||||
)
|
||||
|
||||
type HasTags interface {
|
||||
HasTag(tag string) bool
|
||||
}
|
Loading…
Reference in New Issue