Skip to content

Commit

Permalink
Add --kube-version hidden flag to prep node (#335)
Browse files Browse the repository at this point in the history
Add --kube-version hidden flag to prep node

This commit adds a --kube-version arg to prep node command. This will be used in CAPI boot scripts to simplifying and improve the onboarding process.
Currently marking this as a hidden flag but if this turns out to be useful it can be made visible to the users as well.
  • Loading branch information
Pushkar Acharya authored Nov 16, 2022
1 parent 426a576 commit 9afc973
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cmd/prepNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func init() {
prepNodeCmd.Flags().BoolVarP(&nodeConfig.RemoveExistingPkgs, "remove-existing-pkgs", "r", false, "Will remove previous installation if found (default false)")
prepNodeCmd.Flags().BoolVar(&util.SkipKube, "skip-kube", false, "Skip installing pf9-kube/nodelet on this host")
prepNodeCmd.Flags().MarkHidden("skip-kube")
// At the moment prep-node command only install the kube role. If this changes in future, this option can be changed to something more generic.
prepNodeCmd.Flags().StringVar(&util.KubeVersion, "kube-version", "", "Specific version of pf9-kube to install")
prepNodeCmd.Flags().MarkHidden("kube-version")
prepNodeCmd.Flags().BoolVar(&util.CheckIfOnboarded, "skip-connected", false, "If the node is already connected to the PMK control plane, prep-node will be skipped")

rootCmd.AddCommand(prepNodeCmd)
Expand Down
2 changes: 1 addition & 1 deletion pkg/pmk/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func PrepNode(ctx objects.Config, allClients client.Client, auth keystone.Keysto
hostID := strings.TrimSuffix(output, "\n")
time.Sleep(ctx.WaitPeriod * time.Second)

if err := allClients.Resmgr.AuthorizeHost(hostID, auth.Token); err != nil {
if err := allClients.Resmgr.AuthorizeHost(hostID, auth.Token, util.KubeVersion); err != nil {
errStr := "Error: Unable to authorise host. " + err.Error()
sendSegmentEvent(allClients, errStr, auth, true)
return fmt.Errorf(errStr)
Expand Down
7 changes: 5 additions & 2 deletions pkg/resmgr/resmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

type Resmgr interface {
AuthorizeHost(hostID, token string) error
AuthorizeHost(hostID, token string, version string) error
GetHostId(token string, hostIP []string) []string
HostSatus(token string, hostID string) bool
}
Expand Down Expand Up @@ -44,7 +44,7 @@ func NewResmgr(fqdn string, maxHttpRetry int, minWait, maxWait time.Duration, al
}

// AuthorizeHost registers the host with hostID to the resmgr.
func (c *ResmgrImpl) AuthorizeHost(hostID string, token string) error {
func (c *ResmgrImpl) AuthorizeHost(hostID string, token string, version string) error {
zap.S().Debugf("Authorizing the host: %s with DU: %s", hostID, c.fqdn)

client := rhttp.NewClient()
Expand All @@ -57,6 +57,9 @@ func (c *ResmgrImpl) AuthorizeHost(hostID string, token string) error {
client.Logger = &util.ZapWrapper{}

url := fmt.Sprintf("%s/resmgr/v1/hosts/%s/roles/pf9-kube", c.fqdn, hostID)
if len(version) != 0 {
url = fmt.Sprintf("%s/resmgr/v1/hosts/%s/roles/pf9-kube/versions/%s", c.fqdn, hostID, version)
}
req, err := rhttp.NewRequest("PUT", url, nil)
if err != nil {
return fmt.Errorf("Unable to create a new request: %w", err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ var CheckIfOnboarded bool

// SkipKube skips authorizing kube role during prep-node. Not applicable to bootstrap command
var SkipKube bool

// KubeVersion allows specifying a role version when running prep-node command
var KubeVersion string = ""

var HostDown bool
var EBSPermissions []string
var Route53Permissions []string
Expand Down

0 comments on commit 9afc973

Please sign in to comment.