Skip to content

Commit

Permalink
Remove tags from NodeUp
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciprian Hacman committed Aug 12, 2020
1 parent a25da6d commit b591a0c
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 157 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ test: ${BINDATA_TARGETS} # Run tests locally
go test -v ./...

.PHONY: test-windows
test: ${BINDATA_TARGETS} # Run tests locally
test-windows: ${BINDATA_TARGETS} # Run tests locally
go test -v $(go list ./... | grep -v /nodeup/)

.PHONY: ${DIST}/linux/amd64/nodeup
Expand Down
1 change: 0 additions & 1 deletion nodeup/pkg/bootstrap/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ go_library(
"//upup/pkg/fi/nodeup/local:go_default_library",
"//upup/pkg/fi/nodeup/nodetasks:go_default_library",
"//util/pkg/vfs:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
)
9 changes: 2 additions & 7 deletions nodeup/pkg/bootstrap/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ package bootstrap
import (
"bytes"
"fmt"
"k8s.io/kops/nodeup/pkg/distros"
"os"
"strings"

"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog"
"k8s.io/kops/nodeup/pkg/distros"
"k8s.io/kops/pkg/systemd"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/nodeup/local"
Expand All @@ -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{
Expand Down Expand Up @@ -75,7 +71,6 @@ func (i *Installation) Run() error {

target := &local.LocalTarget{
CacheDir: i.CacheDir,
Tags: tags,
}

checkExisting := true
Expand Down
5 changes: 1 addition & 4 deletions nodeup/pkg/distros/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@ go_library(
],
importpath = "k8s.io/kops/nodeup/pkg/distros",
visibility = ["//visibility:public"],
deps = [
"//upup/pkg/fi/nodeup/tags:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
deps = ["//vendor/k8s.io/klog:go_default_library"],
)
45 changes: 0 additions & 45 deletions nodeup/pkg/distros/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package distros

import (
"k8s.io/klog"
"k8s.io/kops/upup/pkg/fi/nodeup/tags"
)

type Distribution string
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion upup/pkg/fi/nodeup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ go_library(
"//vendor/github.com/aws/aws-sdk-go/aws:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws/session:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/ec2:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
)
1 change: 0 additions & 1 deletion upup/pkg/fi/nodeup/cloudinit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ go_library(
deps = [
"//upup/pkg/fi:go_default_library",
"//upup/pkg/fi/utils:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
)
10 changes: 1 addition & 9 deletions upup/pkg/fi/nodeup/cloudinit/cloud_init_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,7 +31,6 @@ import (
type CloudInitTarget struct {
Config *CloudConfig
out io.Writer
Tags sets.String
}

type AddBehaviour int
Expand All @@ -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
}
Expand All @@ -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
Expand Down
15 changes: 1 addition & 14 deletions upup/pkg/fi/nodeup/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 1 addition & 4 deletions upup/pkg/fi/nodeup/local/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ go_library(
srcs = ["local_target.go"],
importpath = "k8s.io/kops/upup/pkg/fi/nodeup/local",
visibility = ["//visibility:public"],
deps = [
"//upup/pkg/fi:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
],
deps = ["//upup/pkg/fi:go_default_library"],
)
7 changes: 0 additions & 7 deletions upup/pkg/fi/nodeup/local/local_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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:]...)
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/nodeup/nodetasks/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ go_library(
importpath = "k8s.io/kops/upup/pkg/fi/nodeup/nodetasks",
visibility = ["//visibility:public"],
deps = [
"//nodeup/pkg/distros:go_default_library",
"//pkg/apis/kops:go_default_library",
"//pkg/backoff:go_default_library",
"//pkg/kubeconfig:go_default_library",
"//pkg/pki:go_default_library",
"//upup/pkg/fi:go_default_library",
"//upup/pkg/fi/nodeup/cloudinit:go_default_library",
"//upup/pkg/fi/nodeup/local:go_default_library",
"//upup/pkg/fi/nodeup/tags:go_default_library",
"//upup/pkg/fi/utils:go_default_library",
"//util/pkg/hashing:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
Expand Down
24 changes: 13 additions & 11 deletions upup/pkg/fi/nodeup/nodetasks/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -129,13 +129,13 @@ func (p *Package) String() string {
}

func (e *Package) Find(c *fi.Context) (*Package, error) {
target := c.Target.(*local.LocalTarget)
d, _ := distros.FindDistribution("/")

if target.HasTag(tags.TagOSFamilyDebian) {
if d.IsDebianFamily() {
return e.findDpkg(c)
}

if target.HasTag(tags.TagOSFamilyRHEL) {
if d.IsRHELFamily() {
return e.findYum(c)
}

Expand Down Expand Up @@ -270,6 +270,8 @@ func (_ *Package) RenderLocal(t *local.LocalTarget, a, e, changes *Package) erro
packageManagerLock.Lock()
defer packageManagerLock.Unlock()

d, _ := distros.FindDistribution("/")

if a == nil || changes.Version != nil {
klog.Infof("Installing package %q (dependencies: %v)", e.Name, e.Deps)
var pkgs []string
Expand All @@ -283,9 +285,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")
Expand Down Expand Up @@ -315,11 +317,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"}
Expand All @@ -338,7 +340,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:]...)
Expand All @@ -348,7 +350,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 {
Expand Down
Loading

0 comments on commit b591a0c

Please sign in to comment.