Skip to content

Commit

Permalink
Add rancherd bootstrapper
Browse files Browse the repository at this point in the history
fix: #44
  • Loading branch information
innobead committed May 2, 2021
1 parent 13202db commit 5206af0
Show file tree
Hide file tree
Showing 17 changed files with 722 additions and 39 deletions.
1 change: 1 addition & 0 deletions cmd/kubefire/kubefire.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringVarP(&config.LogLevel, "log-level", "l", logrus.InfoLevel.String(), util.FlagsValuesUsage("log level", logrus.AllLevels))
rootCmd.PersistentFlags().StringVarP(&config.GithubToken, "github-token", "t", "", "GIthub Personal Access Token used to query repo release info")
}

func initConfig() {
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/avast/retry-go v2.6.0+incompatible
github.com/containerd/go-cni v1.0.1
github.com/goccy/go-yaml v1.7.5
github.com/golang/protobuf v1.3.3 // indirect
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.0
Expand All @@ -24,9 +23,7 @@ require (
github.com/stretchr/testify v1.6.1
github.com/thoas/go-funk v0.7.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
golang.org/x/sys v0.0.0-20200610111108-226ff32320da // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
Expand Down
320 changes: 314 additions & 6 deletions go.sum

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions internal/cmd/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
)

type BootstrapperVersionInfo struct {
Kubeadm string
K3s string
RKE string
RKE2 string
K0s string
Kubeadm string
K3s string
RKE string
RKE2 string
RANCHERD string
K0s string
}

func BootstrapperVersionInfos() *BootstrapperVersionInfo {
Expand All @@ -25,11 +26,12 @@ func BootstrapperVersionInfos() *BootstrapperVersionInfo {
}

return &BootstrapperVersionInfo{
Kubeadm: versionsMap[constants.KUBEADM],
K3s: versionsMap[constants.K3S],
RKE: versionsMap[constants.RKE],
RKE2: versionsMap[constants.RKE2],
K0s: versionsMap[constants.K0s],
Kubeadm: versionsMap[constants.KUBEADM],
K3s: versionsMap[constants.K3S],
RKE: versionsMap[constants.RKE],
RKE2: versionsMap[constants.RKE2],
RANCHERD: versionsMap[constants.RANCHERD],
K0s: versionsMap[constants.K0s],
}
}

Expand Down
8 changes: 8 additions & 0 deletions internal/config/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var (
LogLevel string
Output string
Bootstrapper string
GithubToken string
)

var (
Expand Down Expand Up @@ -68,6 +69,13 @@ func RKE2VersionsEnvVars(version string, configContent string) EnvVars {
}
}

func RancherdVersionsEnvVars(version string, configContent string) EnvVars {
return []string{
fmt.Sprintf("RANCHERD_VERSION=%s", version),
fmt.Sprintf(`RKE2_CONFIG="%s"`, configContent),
}
}

func K0sVersionsEnvVars(version string, configContent string, cmdOpts string) EnvVars {
return []string{
fmt.Sprintf("K0S_VERSION=%s", version),
Expand Down
27 changes: 23 additions & 4 deletions pkg/bootstrap/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var BuiltinTypes = []string{
constants.K3S,
constants.RKE,
constants.RKE2,
constants.RANCHERD,
constants.K0s,
}

Expand All @@ -49,6 +50,8 @@ func New(bootstrapper string) Bootstrapper {
return NewRKEBootstrapper()
case constants.RKE2:
return NewRKE2Bootstrapper()
case constants.RANCHERD:
return NewRancherdBootstrapper()
case constants.K0s:
return NewK0sBootstrapper()
default:
Expand Down Expand Up @@ -122,7 +125,6 @@ func GenerateSaveBootstrapperVersions(bootstrapperType string, configManager pkg
}

case *versionfinder.K3sVersionFinder:

for _, v := range versions {
bv := pkgconfig.NewK3sBootstrapperVersion(v.String())
bootstrapperVersions = append(bootstrapperVersions, bv)
Expand All @@ -133,7 +135,6 @@ func GenerateSaveBootstrapperVersions(bootstrapperType string, configManager pkg
}

case *versionfinder.RKEVersionFinder:

for _, v := range versions {
bv := pkgconfig.NewRKEBootstrapperVersion(v.String(), v.ExtraMeta["kubernetes_version"].([]string))
bootstrapperVersions = append(bootstrapperVersions, bv)
Expand All @@ -144,7 +145,6 @@ func GenerateSaveBootstrapperVersions(bootstrapperType string, configManager pkg
}

case *versionfinder.RKE2VersionFinder:

for _, v := range versions {
bv := pkgconfig.NewRKE2BootstrapperVersion(v.String())
bootstrapperVersions = append(bootstrapperVersions, bv)
Expand All @@ -154,8 +154,17 @@ func GenerateSaveBootstrapperVersions(bootstrapperType string, configManager pkg
}
}

case *versionfinder.K0sVersionFinder:
case *versionfinder.RancherdVersionFinder:
for _, v := range versions {
bv := pkgconfig.NewRancherdBootstrapperVersion(v.String())
bootstrapperVersions = append(bootstrapperVersions, bv)

if bv.Version() == latestVersion.String() {
bootstrapperLatestVersion = bv
}
}

case *versionfinder.K0sVersionFinder:
for _, v := range versions {
bv := pkgconfig.NewK0sBootstrapperVersion(v.String())
bootstrapperVersions = append(bootstrapperVersions, bv)
Expand All @@ -166,7 +175,17 @@ func GenerateSaveBootstrapperVersions(bootstrapperType string, configManager pkg
}
}

if bootstrapperLatestVersion == nil {
logrus.Warnf(
"ignored to save bootstrapper (%s) versions, because the latest version %s not matched: %v",
bootstrapperType,
latestVersion,
bootstrapperVersions,
)
return
}
if err = configManager.SaveBootstrapperVersions(bootstrapperLatestVersion, bootstrapperVersions); err != nil {
logrus.Errorf("failed to save bootstrapper (%s) verions: %v", bootstrapperType, err)
return
}

Expand Down
Loading

0 comments on commit 5206af0

Please sign in to comment.