Skip to content

Commit

Permalink
Add support for disabling packaged components (charts)
Browse files Browse the repository at this point in the history
Related to #232

Signed-off-by: Brad Davidson <[email protected]>
  • Loading branch information
brandond committed Sep 26, 2020
1 parent 5762b88 commit 5d2ae78
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 14 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ ARG CHARTS_REPO="https://rke2-charts.rancher.io"
ARG CACHEBUST="cachebust"
COPY charts/ /charts/
RUN echo ${CACHEBUST}>/dev/null
RUN CHART_VERSION="v3.13.3" CHART_FILE=/charts/rke2-canal-chart.yml CHART_BOOTSTRAP=true /charts/build-chart.sh
RUN CHART_VERSION="1.10.101" CHART_FILE=/charts/rke2-coredns-chart.yml CHART_BOOTSTRAP=true /charts/build-chart.sh
RUN CHART_VERSION="1.36.300" CHART_FILE=/charts/rke2-ingress-nginx-chart.yml CHART_BOOTSTRAP=false /charts/build-chart.sh
RUN CHART_VERSION="v1.18.9" CHART_FILE=/charts/rke2-kube-proxy-chart.yml CHART_BOOTSTRAP=true /charts/build-chart.sh
RUN CHART_VERSION="2.11.100" CHART_FILE=/charts/rke2-metrics-server-chart.yml CHART_BOOTSTRAP=false /charts/build-chart.sh
RUN CHART_VERSION="v3.13.3" CHART_FILE=/charts/rke2-canal.yaml CHART_BOOTSTRAP=true /charts/build-chart.sh
RUN CHART_VERSION="1.10.101" CHART_FILE=/charts/rke2-coredns.yaml CHART_BOOTSTRAP=true /charts/build-chart.sh
RUN CHART_VERSION="1.36.300" CHART_FILE=/charts/rke2-ingress-nginx.yaml CHART_BOOTSTRAP=false /charts/build-chart.sh
RUN CHART_VERSION="v1.18.9" CHART_FILE=/charts/rke2-kube-proxy.yaml CHART_BOOTSTRAP=true /charts/build-chart.sh
RUN CHART_VERSION="2.11.100" CHART_FILE=/charts/rke2-metrics-server.yaml CHART_BOOTSTRAP=false /charts/build-chart.sh
RUN rm -vf /charts/*.sh /charts/*.md

# rke-runtime image
Expand Down
2 changes: 1 addition & 1 deletion charts/build-chart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -eux -o pipefail

: "${CHART_FILE?required}"
: "${CHART_NAME:="$(basename "${CHART_FILE%%-chart.yml}")"}"
: "${CHART_NAME:="$(basename "${CHART_FILE%%.yaml}")"}"
: "${CHART_URL:="${CHART_REPO:="https://rke2-charts.rancher.io"}/assets/${CHART_NAME}/${CHART_NAME}-${CHART_VERSION:="v0.0.0"}.tgz"}"
curl -fsSL "${CHART_URL}" -o "${CHART_TMP:=$(mktemp)}"
cat <<-EOF > "${CHART_FILE}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Create a new release asset for in the [rke2-charts](github.com/rancher/rke2-char

The following files have references that will need to be updated in the respective locations. Replace the found version with the desired version.

* Dockerfile: `RUN CHART_VERSION="v1.18.9" CHART_FILE=/charts/rke2-kube-proxy-chart.yml`
* Dockerfile: `RUN CHART_VERSION="v1.18.9" CHART_FILE=/charts/rke2-kube-proxy.yaml`
* Dockerfile: `FROM rancher/k3s:v1.18.9-k3s1 AS k3s`
* images.go: `KubernetesVersion = "v1.18.9"`
* version.sh: `KUBERNETES_VERSION=${KUBERNETES_VERSION:-v1.18.9}`
46 changes: 46 additions & 0 deletions pkg/cli/cmds/k3sopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,33 @@ func commandFromK3S(cmd cli.Command, flagOpts map[string]*K3SFlagOption) (cli.Co
strFlag.Hidden = true
}
flag = strFlag
} else if strFlag, ok := flag.(*cli.StringFlag); ok {
if opt.Usage != "" {
strFlag.Usage = opt.Usage
}
if opt.Default != "" {
strFlag.Value = opt.Default
}
if opt.Hide {
strFlag.Hidden = true
}
flag = strFlag
} else if strSliceFlag, ok := flag.(cli.StringSliceFlag); ok {
if opt.Usage != "" {
strSliceFlag.Usage = opt.Usage
}
if opt.Default != "" {
slice := &cli.StringSlice{}
parts := strings.Split(opt.Default, ",")
for _, val := range parts {
slice.Set(val)
}
strSliceFlag.Value = slice
}
if opt.Hide {
strSliceFlag.Hidden = true
}
flag = strSliceFlag
} else if intFlag, ok := flag.(cli.IntFlag); ok {
if opt.Usage != "" {
intFlag.Usage = opt.Usage
Expand All @@ -75,6 +102,14 @@ func commandFromK3S(cmd cli.Command, flagOpts map[string]*K3SFlagOption) (cli.Co
intFlag.Hidden = true
}
flag = intFlag
} else if intFlag, ok := flag.(*cli.IntFlag); ok {
if opt.Usage != "" {
intFlag.Usage = opt.Usage
}
if opt.Hide {
intFlag.Hidden = true
}
flag = intFlag
} else if boolFlag, ok := flag.(cli.BoolFlag); ok {
if opt.Usage != "" {
boolFlag.Usage = opt.Usage
Expand All @@ -83,7 +118,18 @@ func commandFromK3S(cmd cli.Command, flagOpts map[string]*K3SFlagOption) (cli.Co
boolFlag.Hidden = true
}
flag = boolFlag
} else if boolFlag, ok := flag.(*cli.BoolFlag); ok {
if opt.Usage != "" {
boolFlag.Usage = opt.Usage
}
if opt.Hide {
boolFlag.Hidden = true
}
flag = boolFlag
} else {
errs = append(errs, fmt.Errorf("unsupported type %T for flag %s", flag, name))
}

newFlags = append(newFlags, flag)
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/cli/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
"github.com/urfave/cli"
)

const rke2Path = "/var/lib/rancher/rke2"
const (
DisableItems = "rke2-canal, rke2-coredns, rke2-ingress, rke2-kube-proxy, rke2-metrics-server"
rke2Path = "/var/lib/rancher/rke2"
)

var (
config rke2.Config
Expand Down Expand Up @@ -53,8 +56,7 @@ var (
"datastore-keyfile": drop,
"default-local-storage-path": drop,
"disable": {
Hide: true,
Default: cmds.DisableItems,
Usage: "(components) Do not deploy packaged components and delete any deployed components (valid items: " + DisableItems + ")",
},
"disable-selinux": drop,
"disable-scheduler": drop,
Expand Down
6 changes: 2 additions & 4 deletions pkg/rke2/rke2.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ func Server(clx *cli.Context, cfg Config) error {
if err := setup(clx, cfg); err != nil {
return err
}
if err := clx.Set("disable", cmds.DisableItems); err != nil {
return err
}
if err := clx.Set("secrets-encryption", "true"); err != nil {
return err
}
Expand All @@ -57,11 +54,12 @@ func Agent(clx *cli.Context, cfg Config) error {

func setup(clx *cli.Context, cfg Config) error {
var dataDir string

for _, f := range clx.Command.Flags {
switch t := f.(type) {
case cli.StringFlag:
if strings.Contains(t.Name, "data-dir") {
dataDir = t.Value
dataDir = *t.Destination
}
}
}
Expand Down

0 comments on commit 5d2ae78

Please sign in to comment.