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 c093453
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 145 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
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
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
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
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
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
19 changes: 10 additions & 9 deletions upup/pkg/fi/nodeup/nodetasks/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package nodetasks
import (
"fmt"
"io/ioutil"
"k8s.io/kops/nodeup/pkg/distros"
"os"
"os/exec"
"path"
Expand All @@ -29,7 +30,6 @@ import (
"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 (
Expand Down Expand Up @@ -126,22 +126,23 @@ 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, _ := distros.FindDistribution("/")
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")
}
}

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
}
Expand Down Expand Up @@ -239,7 +240,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
}
Expand Down Expand Up @@ -355,7 +356,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
}
Expand Down
7 changes: 4 additions & 3 deletions upup/pkg/fi/nodeup/nodetasks/update_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package nodetasks

import (
"fmt"
"k8s.io/kops/nodeup/pkg/distros"
"os"
"os/exec"
"syscall"
Expand All @@ -26,7 +27,6 @@ import (
"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 {
Expand Down Expand Up @@ -65,11 +65,12 @@ func (_ *UpdatePackages) RenderLocal(t *local.LocalTarget, a, e, changes *Update
klog.Infof("SKIP_PACKAGE_UPDATE was set; skipping package update")
return nil
}
d, _ := distros.FindDistribution("/")
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 {
Expand Down
Loading

0 comments on commit c093453

Please sign in to comment.