Remove unused Tags from NodeUp

This commit is contained in:
Ciprian Hacman 2020-08-12 11:43:02 +03:00
parent 04416c38f5
commit d75042cc85
10 changed files with 43 additions and 143 deletions

View File

@ -22,7 +22,6 @@ import (
"os" "os"
"strings" "strings"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog" "k8s.io/klog"
"k8s.io/kops/nodeup/pkg/distros" "k8s.io/kops/nodeup/pkg/distros"
"k8s.io/kops/pkg/systemd" "k8s.io/kops/pkg/systemd"
@ -40,14 +39,11 @@ type Installation struct {
} }
func (i *Installation) Run() error { func (i *Installation) Run() error {
distribution, err := distros.FindDistribution(i.FSRoot) _, err := distros.FindDistribution(i.FSRoot)
if err != nil { if err != nil {
return fmt.Errorf("error determining OS distribution: %v", err) return fmt.Errorf("error determining OS distribution: %v", err)
} }
tags := sets.NewString()
tags.Insert(distribution.BuildTags()...)
tasks := make(map[string]fi.Task) tasks := make(map[string]fi.Task)
buildContext := &fi.ModelBuilderContext{ buildContext := &fi.ModelBuilderContext{
@ -75,7 +71,6 @@ func (i *Installation) Run() error {
target := &local.LocalTarget{ target := &local.LocalTarget{
CacheDir: i.CacheDir, CacheDir: i.CacheDir,
Tags: tags,
} }
checkExisting := true checkExisting := true

View File

@ -18,7 +18,6 @@ package distros
import ( import (
"k8s.io/klog" "k8s.io/klog"
"k8s.io/kops/upup/pkg/fi/nodeup/tags"
) )
type Distribution string type Distribution string
@ -38,50 +37,6 @@ var (
DistributionContainerOS Distribution = "containeros" 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 { func (d Distribution) IsDebianFamily() bool {
switch d { switch d {
case DistributionDebian9, DistributionDebian10: case DistributionDebian9, DistributionDebian10:

View File

@ -23,7 +23,6 @@ import (
"os" "os"
"path" "path"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog" "k8s.io/klog"
"k8s.io/kops/upup/pkg/fi" "k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/utils" "k8s.io/kops/upup/pkg/fi/utils"
@ -32,7 +31,6 @@ import (
type CloudInitTarget struct { type CloudInitTarget struct {
Config *CloudConfig Config *CloudConfig
out io.Writer out io.Writer
Tags sets.String
} }
type AddBehaviour int type AddBehaviour int
@ -42,11 +40,10 @@ const (
Once Once
) )
func NewCloudInitTarget(out io.Writer, tags sets.String) *CloudInitTarget { func NewCloudInitTarget(out io.Writer) *CloudInitTarget {
t := &CloudInitTarget{ t := &CloudInitTarget{
Config: &CloudConfig{}, Config: &CloudConfig{},
out: out, out: out,
Tags: tags,
} }
return t return t
} }
@ -69,11 +66,6 @@ type CloudConfigFile struct {
Content string `json:"content,omitempty"` Content string `json:"content,omitempty"`
} }
func (t *CloudInitTarget) HasTag(tag string) bool {
_, found := t.Tags[tag]
return found
}
func (t *CloudInitTarget) ProcessDeletions() bool { func (t *CloudInitTarget) ProcessDeletions() bool {
// We don't expect any, but it would be our job to process them // We don't expect any, but it would be our job to process them
return true return true

View File

@ -46,7 +46,6 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog" "k8s.io/klog"
) )
@ -163,22 +162,11 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
return fmt.Errorf("error determining OS architecture: %v", err) return fmt.Errorf("error determining OS architecture: %v", err)
} }
archTags := architecture.BuildTags()
distribution, err := distros.FindDistribution(c.FSRoot) distribution, err := distros.FindDistribution(c.FSRoot)
if err != nil { if err != nil {
return fmt.Errorf("error determining OS distribution: %v", err) 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] configAssets := c.config.Assets[architecture]
assetStore := fi.NewAssetStore(c.CacheDir) assetStore := fi.NewAssetStore(c.CacheDir)
for _, asset := range configAssets { for _, asset := range configAssets {
@ -290,14 +278,13 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
case "direct": case "direct":
target = &local.LocalTarget{ target = &local.LocalTarget{
CacheDir: c.CacheDir, CacheDir: c.CacheDir,
Tags: nodeTags,
} }
case "dryrun": case "dryrun":
assetBuilder := assets.NewAssetBuilder(c.cluster, "") assetBuilder := assets.NewAssetBuilder(c.cluster, "")
target = fi.NewDryRunTarget(assetBuilder, out) target = fi.NewDryRunTarget(assetBuilder, out)
case "cloudinit": case "cloudinit":
checkExisting = false checkExisting = false
target = cloudinit.NewCloudInitTarget(out, nodeTags) target = cloudinit.NewCloudInitTarget(out)
default: default:
return fmt.Errorf("unsupported target type %q", c.Target) return fmt.Errorf("unsupported target type %q", c.Target)
} }

View File

@ -19,13 +19,11 @@ package local
import ( import (
"os/exec" "os/exec"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kops/upup/pkg/fi" "k8s.io/kops/upup/pkg/fi"
) )
type LocalTarget struct { type LocalTarget struct {
CacheDir string CacheDir string
Tags sets.String
} }
var _ fi.Target = &LocalTarget{} var _ fi.Target = &LocalTarget{}
@ -39,11 +37,6 @@ func (t *LocalTarget) ProcessDeletions() bool {
return true 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 // CombinedOutput is a helper function that executes a command, returning stdout & stderr combined
func (t *LocalTarget) CombinedOutput(args []string) ([]byte, error) { func (t *LocalTarget) CombinedOutput(args []string) ([]byte, error) {
c := exec.Command(args[0], args[1:]...) c := exec.Command(args[0], args[1:]...)

View File

@ -26,11 +26,11 @@ import (
"sync" "sync"
"k8s.io/klog" "k8s.io/klog"
"k8s.io/kops/nodeup/pkg/distros"
"k8s.io/kops/pkg/apis/kops" "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi" "k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/nodeup/cloudinit" "k8s.io/kops/upup/pkg/fi/nodeup/cloudinit"
"k8s.io/kops/upup/pkg/fi/nodeup/local" "k8s.io/kops/upup/pkg/fi/nodeup/local"
"k8s.io/kops/upup/pkg/fi/nodeup/tags"
"k8s.io/kops/util/pkg/hashing" "k8s.io/kops/util/pkg/hashing"
) )
@ -129,13 +129,16 @@ func (p *Package) String() string {
} }
func (e *Package) Find(c *fi.Context) (*Package, error) { 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) return e.findDpkg(c)
} }
if target.HasTag(tags.TagOSFamilyRHEL) { if d.IsRHELFamily() {
return e.findYum(c) return e.findYum(c)
} }
@ -270,6 +273,11 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
packageManagerLock.Lock() packageManagerLock.Lock()
defer packageManagerLock.Unlock() 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 { if a == nil || changes.Version != nil {
klog.Infof("Installing package %q (dependencies: %v)", e.Name, e.Deps) klog.Infof("Installing package %q (dependencies: %v)", e.Name, e.Deps)
var pkgs []string var pkgs []string
@ -283,9 +291,9 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
// Append file extension for local files // Append file extension for local files
var ext string var ext string
if t.HasTag(tags.TagOSFamilyDebian) { if d.IsDebianFamily() {
ext = ".deb" ext = ".deb"
} else if t.HasTag(tags.TagOSFamilyRHEL) { } else if d.IsRHELFamily() {
ext = ".rpm" ext = ".rpm"
} else { } else {
return fmt.Errorf("unsupported package system") return fmt.Errorf("unsupported package system")
@ -315,11 +323,11 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
var args []string var args []string
env := os.Environ() env := os.Environ()
if t.HasTag(tags.TagOSFamilyDebian) { if d.IsDebianFamily() {
args = []string{"apt-get", "install", "--yes", "--no-install-recommends"} args = []string{"apt-get", "install", "--yes", "--no-install-recommends"}
env = append(env, "DEBIAN_FRONTEND=noninteractive") env = append(env, "DEBIAN_FRONTEND=noninteractive")
} else if t.HasTag(tags.TagOSFamilyRHEL) { } else if d.IsRHELFamily() {
if t.HasTag(tags.TagOSCentOS8) || t.HasTag(tags.TagOSRHEL8) { if d == distros.DistributionCentos8 || d == distros.DistributionRhel8 {
args = []string{"/usr/bin/dnf", "install", "-y", "--setopt=install_weak_deps=False"} args = []string{"/usr/bin/dnf", "install", "-y", "--setopt=install_weak_deps=False"}
} else { } else {
args = []string{"/usr/bin/yum", "install", "-y"} args = []string{"/usr/bin/yum", "install", "-y"}
@ -338,7 +346,7 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
} }
} else { } else {
if changes.Healthy != nil { if changes.Healthy != nil {
if t.HasTag(tags.TagOSFamilyDebian) { if d.IsDebianFamily() {
args := []string{"dpkg", "--configure", "-a"} args := []string{"dpkg", "--configure", "-a"}
klog.Infof("package is not healthy; running command %s", args) klog.Infof("package is not healthy; running command %s", args)
cmd := exec.Command(args[0], args[1:]...) 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 changes.Healthy = nil
} else if t.HasTag(tags.TagOSFamilyRHEL) { } else if d.IsRHELFamily() {
// Not set on TagOSFamilyRHEL, we can't currently reach here anyway... // Not set on TagOSFamilyRHEL, we can't currently reach here anyway...
return fmt.Errorf("package repair not supported on RHEL/CentOS") return fmt.Errorf("package repair not supported on RHEL/CentOS")
} else { } else {

View File

@ -26,10 +26,10 @@ import (
"time" "time"
"k8s.io/klog" "k8s.io/klog"
"k8s.io/kops/nodeup/pkg/distros"
"k8s.io/kops/upup/pkg/fi" "k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/nodeup/cloudinit" "k8s.io/kops/upup/pkg/fi/nodeup/cloudinit"
"k8s.io/kops/upup/pkg/fi/nodeup/local" "k8s.io/kops/upup/pkg/fi/nodeup/local"
"k8s.io/kops/upup/pkg/fi/nodeup/tags"
) )
const ( const (
@ -126,14 +126,19 @@ func getSystemdStatus(name string) (map[string]string, error) {
return properties, nil return properties, nil
} }
func (e *Service) systemdSystemPath(target tags.HasTags) (string, error) { func (e *Service) systemdSystemPath() (string, error) {
if target.HasTag(tags.TagOSFamilyDebian) { d, err := distros.FindDistribution("/")
if err != nil {
return "", fmt.Errorf("unknown or unsupported distro: %v", err)
}
if d.IsDebianFamily() {
return debianSystemdSystemPath, nil return debianSystemdSystemPath, nil
} else if target.HasTag(tags.TagOSFamilyRHEL) { } else if d.IsRHELFamily() {
return centosSystemdSystemPath, nil return centosSystemdSystemPath, nil
} else if target.HasTag("_flatcar") { } else if d == distros.DistributionFlatcar {
return flatcarSystemdSystemPath, nil return flatcarSystemdSystemPath, nil
} else if target.HasTag("_containeros") { } else if d == distros.DistributionContainerOS {
return containerosSystemdSystemPath, nil return containerosSystemdSystemPath, nil
} else { } else {
return "", fmt.Errorf("unsupported systemd system") 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) { func (e *Service) Find(c *fi.Context) (*Service, error) {
systemdSystemPath, err := e.systemdSystemPath(c.Target.(tags.HasTags)) systemdSystemPath, err := e.systemdSystemPath()
if err != nil { if err != nil {
return nil, err 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 { func (_ *Service) RenderLocal(t *local.LocalTarget, a, e, changes *Service) error {
systemdSystemPath, err := e.systemdSystemPath(t) systemdSystemPath, err := e.systemdSystemPath()
if err != nil { if err != nil {
return err 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 { func (_ *Service) RenderCloudInit(t *cloudinit.CloudInitTarget, a, e, changes *Service) error {
systemdSystemPath, err := e.systemdSystemPath(t) systemdSystemPath, err := e.systemdSystemPath()
if err != nil { if err != nil {
return err return err
} }

View File

@ -23,10 +23,10 @@ import (
"syscall" "syscall"
"k8s.io/klog" "k8s.io/klog"
"k8s.io/kops/nodeup/pkg/distros"
"k8s.io/kops/upup/pkg/fi" "k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/nodeup/cloudinit" "k8s.io/kops/upup/pkg/fi/nodeup/cloudinit"
"k8s.io/kops/upup/pkg/fi/nodeup/local" "k8s.io/kops/upup/pkg/fi/nodeup/local"
"k8s.io/kops/upup/pkg/fi/nodeup/tags"
) )
type UpdatePackages struct { 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") klog.Infof("SKIP_PACKAGE_UPDATE was set; skipping package update")
return nil return nil
} }
d, err := distros.FindDistribution("/")
if err != nil {
return fmt.Errorf("unknown or unsupported distro: %v", err)
}
var args []string var args []string
if t.HasTag(tags.TagOSFamilyDebian) { if d.IsDebianFamily() {
args = []string{"apt-get", "update"} args = []string{"apt-get", "update"}
} else if t.HasTag(tags.TagOSFamilyRHEL) { } else if d.IsRHELFamily() {
// Probably not technically needed // Probably not technically needed
args = []string{"/usr/bin/yum", "check-update"} args = []string{"/usr/bin/yum", "check-update"}
} else { } else {

View File

@ -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"],
)

View File

@ -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
}