Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
Remove footloose references
Browse files Browse the repository at this point in the history
  • Loading branch information
luxas committed Jul 17, 2020
1 parent 7f03c64 commit 19b1c53
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 75 deletions.
28 changes: 7 additions & 21 deletions cmd/wksctl/init/init.go
Expand Up @@ -25,8 +25,6 @@ import (

type initOptionType struct {
dependencyPath string
footlooseIP string
footlooseBackend string
gitURL string
gitBranch string
gitPath string
Expand Down Expand Up @@ -56,15 +54,13 @@ var (

initOptions initOptionType

namespacePrefixPattern = "kind: Namespace\n metadata:\n name: "
namespaceNamePattern = multiLineRegexp(namespacePrefixPattern + `\S+`)
controllerFootlooseAddrLocation = multiLineRegexp(`(\s*)- name: controller`)
controllerFootlooseEnvEntry = multiLineRegexp(`env:\n\s*- name: FOOTLOOSE_SERVER_ADDR`)
controllerImageSegment = multiLineRegexp(`(image:\s*\S*[-]controller)(:\s*\S+)?`)
namespacePattern = multiLineRegexp(`namespace:\s*\S+`)
gitURLPattern = multiLineRegexp(`(--git-url)=\S+`)
gitBranchPattern = multiLineRegexp(`(--git-branch)=\S+`)
gitPathPattern = multiLineRegexp(`(--git-path)=\S+`)
namespacePrefixPattern = "kind: Namespace\n metadata:\n name: "
namespaceNamePattern = multiLineRegexp(namespacePrefixPattern + `\S+`)
controllerImageSegment = multiLineRegexp(`(image:\s*\S*[-]controller)(:\s*\S+)?`)
namespacePattern = multiLineRegexp(`namespace:\s*\S+`)
gitURLPattern = multiLineRegexp(`(--git-url)=\S+`)
gitBranchPattern = multiLineRegexp(`(--git-branch)=\S+`)
gitPathPattern = multiLineRegexp(`(--git-path)=\S+`)

updates = []manifestUpdate{
{name: "weave-net", selector: equal("weave-net.yaml"), updater: updateWeaveNetManifests},
Expand All @@ -79,10 +75,6 @@ func multiLineRegexp(pattern string) *regexp.Regexp {
}

func init() {
Cmd.Flags().StringVar(
&initOptions.footlooseIP, "footloose-ip", "172.17.0.1", "address of footloose server on host")
Cmd.Flags().StringVar(
&initOptions.footlooseBackend, "footloose-backend", "docker", "which machine backend to use: ignite or docker")
Cmd.Flags().StringVar(
&initOptions.localRepoDirectory, "gitk8s-clone", ".", "Local location of cloned git repository")
Cmd.Flags().StringVar(&initOptions.gitURL, "git-url", "",
Expand Down Expand Up @@ -145,12 +137,6 @@ func updateControllerManifests(contents []byte, options initOptionType) ([]byte,
} else {
withVersion = controllerImageSegment.ReplaceAll(contents, []byte(`$1:`+controllerVersion))
}
if controllerFootlooseEnvEntry.Find(withVersion) == nil {
return controllerFootlooseAddrLocation.ReplaceAll(withVersion,
// We want to add to the matched entry so we start with $0 (the entire match) and use $1 to get the indentation correct.
// The $1 contains a leading newline.
[]byte(fmt.Sprintf("$0$1 env:$1 - name: FOOTLOOSE_SERVER_ADDR$1 value: %s$1 - name: FOOTLOOSE_BACKEND$1 value: %s", options.footlooseIP, options.footlooseBackend))), nil
}
return withVersion, nil
}

Expand Down
9 changes: 1 addition & 8 deletions cmd/wksctl/init/init_test.go
Expand Up @@ -274,11 +274,6 @@ spec:
operator: Exists
containers:
- name: controller
env:
- name: FOOTLOOSE_SERVER_ADDR
value: 192.168.51.1:28496
- name: FOOTLOOSE_BACKEND
value: docker
image: docker.io/weaveworks/wksctl-controller:version1.2.3
command:
- /bin/controller
Expand All @@ -295,9 +290,7 @@ spec:
func TestControllerTranslate(t *testing.T) {
res, err := updateControllerManifests([]byte(controllerInputs),
initOptionType{
version: "version1.2.3",
footlooseIP: "192.168.51.1:28496",
footlooseBackend: "docker",
version: "version1.2.3",
})
assert.NoError(t, err)
assert.Equal(t, string(res), controllerOutputs)
Expand Down
48 changes: 2 additions & 46 deletions pkg/apis/wksprovider/controller/wksctl/machine_controller.go
Expand Up @@ -7,14 +7,11 @@ import (
"fmt"
"io"
"math/rand"
goos "os"
"strings"
"time"

gerrors "github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/weaveworks/footloose/pkg/cluster"
fconfig "github.com/weaveworks/footloose/pkg/config"
"github.com/weaveworks/wksctl/pkg/apis/wksprovider/machine/config"
"github.com/weaveworks/wksctl/pkg/apis/wksprovider/machine/os"
baremetalspecv1 "github.com/weaveworks/wksctl/pkg/baremetal/v1alpha3"
Expand Down Expand Up @@ -57,29 +54,9 @@ const (
)

var (
footlooseAddr = "<unknown>"
footlooseBackend = "docker"
machineIPs = map[string]string{}
machineIPs = map[string]string{}
)

// STOPGAP: copy of machine def from footloose; the footloose version has private fields
type FootlooseMachine struct {
Spec *fconfig.Machine `json:"spec"`

// container name.
Name string `json:"name"`
// container hostname.
Hostname string `json:"hostname"`
// container ip.
IP string `json:"ip,omitempty"`

RuntimeNetworks []*cluster.RuntimeNetwork `json:"runtimeNetworks,omitempty"`
// Fields that are cached from the docker daemon.

Ports map[int]int `json:"ports,omitempty"`
// maps containerPort -> hostPort.
}

// TODO: should this be renamed 'reconciler' to match other CAPI providers ?

// MachineController is responsible for managing this cluster's machines, and
Expand Down Expand Up @@ -179,18 +156,6 @@ func (a *MachineController) create(ctx context.Context, installer *os.OS, c *bar
contextLog := log.WithFields(log.Fields{"machine": machine.Name, "cluster": c.Name})
contextLog.Info("creating machine...")

// Also, update footloose IP from env
log.Infof("FETCHING FOOTLOOSE ADDRESS...")
fip := goos.Getenv("FOOTLOOSE_SERVER_ADDR")
if fip != "" {
footlooseAddr = fip
}
backend := goos.Getenv("FOOTLOOSE_BACKEND")
if backend != "" {
footlooseBackend = backend
}
log.Infof("FOOTLOOSE ADDR: %s", footlooseAddr)
log.Infof("FOOTLOOSE BACKEND: %s", footlooseBackend)
nodePlan, err := a.getNodePlan(ctx, c, machine, a.getMachineAddress(bmm), installer)
if err != nil {
return err
Expand Down Expand Up @@ -1003,12 +968,6 @@ func (a *MachineController) getControllerNodeName(ctx context.Context) (string,
return "", err
}

//nolint:unused
// TODO: Remove if really unused
func (a *MachineController) updateMachine(machine *baremetalspecv1.BareMetalMachine, ip string) {
machineIPs[getMachineID(machine)] = ip
}

func isMaster(node *corev1.Node) bool {
_, isMaster := node.Labels[masterLabel]
return isMaster
Expand Down Expand Up @@ -1040,10 +999,7 @@ func getMachineID(machine *baremetalspecv1.BareMetalMachine) string {
}

func (a *MachineController) getMachineAddress(m *baremetalspecv1.BareMetalMachine) string {
if m.Spec.Private.Address != "" {
return m.Spec.Private.Address
}
return machineIPs[getMachineID(m)]
return m.Spec.Private.Address
}

func (a *MachineController) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
Expand Down

0 comments on commit 19b1c53

Please sign in to comment.