Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Juniper request : skip installer download #356

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/prepNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func init() {
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")

prepNodeCmd.Flags().BoolVar(&util.SkipInstallerDownload, "skip-installer-download", false, "If set then installer will not be downloaded")
prepNodeCmd.Flags().MarkHidden("skip-installer-download")
rootCmd.AddCommand(prepNodeCmd)
}

Expand Down
141 changes: 93 additions & 48 deletions pkg/pmk/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const (
HostAgentLegacy = 404
)

var (
// Building our new spinner
s = spinner.New(spinner.CharSets[9], 100*time.Millisecond)
)

// Sends an event to segment based on the input string and uses auth as keystone UUID property.
func sendSegmentEvent(allClients client.Client, eventStr string, auth keystone.KeystoneAuth, isError bool) {

Expand Down Expand Up @@ -58,8 +63,6 @@ func sendSegmentEvent(allClients client.Client, eventStr string, auth keystone.K

// PrepNode sets up prerequisites for k8s stack
func PrepNode(ctx objects.Config, allClients client.Client, auth keystone.KeystoneAuth) error {
// Building our new spinner
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Color("red")

zap.S().Debug("Received a call to start preparing node(s).")
Expand Down Expand Up @@ -109,7 +112,7 @@ func PrepNode(ctx objects.Config, allClients client.Client, auth keystone.Keysto
}

sendSegmentEvent(allClients, "Installing hostagent - 2", auth, false)
s.Suffix = " Downloading the Hostagent (this might take a few minutes...)"

if err := installHostAgent(ctx, auth, hostOS, allClients.Executor); err != nil {
errStr := "Error: Unable to install hostagent. " + err.Error()
sendSegmentEvent(allClients, errStr, auth, true)
Expand Down Expand Up @@ -264,28 +267,43 @@ func installHostAgent(ctx objects.Config, auth keystone.KeystoneAuth, hostOS str
}

func installHostAgentCertless(ctx objects.Config, regionURL string, auth keystone.KeystoneAuth, hostOS string, exec cmdexec.Executor) error {
zap.S().Debug("Downloading the installer (this might take a few minutes...)")

url := fmt.Sprintf(
"https://%s/clarity/platform9-install-%s.sh",
regionURL, hostOS)
insecureDownload := ""
if ctx.AllowInsecure {
insecureDownload = "-k"
}

homeDir, err := createDirToDownloadInstaller(exec)
var err error
homeDir, err = createDirToDownloadInstaller(exec)
if err != nil {
return err
}

cmd := fmt.Sprintf(`curl %s --silent --show-error %s -o %s/pf9/installer.sh`, insecureDownload, url, homeDir)
_, err = exec.RunWithStdout("bash", "-c", cmd)
if !util.SkipInstallerDownload {
s.Suffix = " Downloading the Hostagent (this might take a few minutes...)"
zap.S().Debug("Downloading the installer (this might take a few minutes...)")
err = downloadCertLessInstaller(ctx, regionURL, hostOS, exec)
if err != nil {
return err
}
} else {
s.Suffix = " Skipped Installer Download, Installing hostagent"
zap.S().Debug("User skiped installer download")
}

err = callCertLessInstaller(ctx, regionURL, auth, exec)

removeTempDirAndInstaller(exec)

if err != nil {
return err
_, exitCode := cmdexec.ExitCodeChecker(err)
fmt.Printf("\n")
fmt.Println("Error :", util.InstallerErrors[exitCode])
zap.S().Debugf("Error:%s", util.InstallerErrors[exitCode])
return fmt.Errorf("error while running installer script: %s", util.InstallerErrors[exitCode])
}
zap.S().Debug("Hostagent download completed successfully")

// TODO: here we actually need additional validation by checking /tmp/agent_install. log
zap.S().Debug("Platform9 packages installed successfully")
return nil
}

func callCertLessInstaller(ctx objects.Config, regionURL string, auth keystone.KeystoneAuth, exec cmdexec.Executor) error {
var installOptions string

//Pass keystone token if MFA token is provided
Expand All @@ -299,11 +317,12 @@ func installHostAgentCertless(ctx objects.Config, regionURL string, auth keyston
}

changePermission := fmt.Sprintf("chmod +x %s/pf9/installer.sh", homeDir)
_, err = exec.RunWithStdout("bash", "-c", changePermission)
_, err := exec.RunWithStdout("bash", "-c", changePermission)
if err != nil {
return err
}

var cmd string
if ctx.ProxyURL != "" {
cmd = fmt.Sprintf(`%s/pf9/installer.sh --proxy %s --skip-os-check --no-ntp`, homeDir, ctx.ProxyURL)
} else {
Expand All @@ -317,19 +336,24 @@ func installHostAgentCertless(ctx objects.Config, regionURL string, auth keyston
cmd = fmt.Sprintf(`%s %s`, cmd, installOptions)
_, err = exec.RunWithStdout("bash", "-c", cmd)
}
return err
}

removeTempDirAndInstaller(exec)
func downloadCertLessInstaller(ctx objects.Config, regionURL string, hostOS string, exec cmdexec.Executor) error {
url := fmt.Sprintf(
"https://%s/clarity/platform9-install-%s.sh",
regionURL, hostOS)
insecureDownload := ""
if ctx.AllowInsecure {
insecureDownload = "-k"
}

cmd := fmt.Sprintf(`curl %s --silent --show-error %s -o %s/pf9/installer.sh`, insecureDownload, url, homeDir)
_, err := exec.RunWithStdout("bash", "-c", cmd)
if err != nil {
_, exitCode := cmdexec.ExitCodeChecker(err)
fmt.Printf("\n")
fmt.Println("Error :", util.InstallerErrors[exitCode])
zap.S().Debugf("Error:%s", util.InstallerErrors[exitCode])
return fmt.Errorf("error while running installer script: %s", util.InstallerErrors[exitCode])
return err
}

// TODO: here we actually need additional validation by checking /tmp/agent_install. log
zap.S().Debug("Platform9 packages installed successfully")
zap.S().Debug("Hostagent download completed successfully")
return nil
}

Expand Down Expand Up @@ -420,56 +444,77 @@ func pf9PackagesPresent(hostOS string, exec cmdexec.Executor) bool {
}

func installHostAgentLegacy(ctx objects.Config, regionURL string, auth keystone.KeystoneAuth, hostOS string, exec cmdexec.Executor) error {
zap.S().Debug("Downloading Hostagent Installer Legacy")

url := fmt.Sprintf("https://%s/private/platform9-install-%s.sh", regionURL, hostOS)

homeDir, err := createDirToDownloadInstaller(exec)
var err error
homeDir, err = createDirToDownloadInstaller(exec)
if err != nil {
return err
}

installOptions := fmt.Sprintf("--insecure --project-name=%s 2>&1 | tee -a %s/pf9/agent_install", auth.ProjectID, homeDir)
//use insecure by default
cmd := fmt.Sprintf(`curl --insecure --silent --show-error -H 'X-Auth-Token:%s' %s -o %s/pf9/installer.sh`, auth.Token, url, homeDir)
_, err = exec.RunWithStdout("bash", "-c", cmd)
if !util.SkipInstallerDownload {
s.Suffix = " Downloading the Hostagent (this might take a few minutes...)"
zap.S().Debug("Downloading Hostagent Installer Legacy")
err = downloadLegacyInstaller(regionURL, auth, hostOS, exec)
if err != nil {
return err
}
} else {
s.Suffix = " Skipped Installer Download, Installing hostagent"
zap.S().Debug("User skiped installer download")
}

err = callLegacyInstaller(ctx, auth, exec)

removeTempDirAndInstaller(exec)

if err != nil {
return err
_, exitCode := cmdexec.ExitCodeChecker(err)
fmt.Printf("\n")
zap.S().Debugf("Error:%s", util.InstallerErrors[exitCode])
fmt.Println("Error :", util.InstallerErrors[exitCode])
return fmt.Errorf("error while running installer script: %s", util.InstallerErrors[exitCode])
}

zap.S().Debug("Hostagent download completed successfully")
// TODO: here we actually need additional validation by checking /tmp/agent_install. log
zap.S().Debug("Hostagent installed successfully")
return nil
}

func callLegacyInstaller(ctx objects.Config, auth keystone.KeystoneAuth, exec cmdexec.Executor) error {
changePermission := fmt.Sprintf("chmod +x %s/pf9/installer.sh", homeDir)
_, err = exec.RunWithStdout("bash", "-c", changePermission)
_, err := exec.RunWithStdout("bash", "-c", changePermission)
if err != nil {
return err
}

var cmd string
if ctx.ProxyURL != "" {
cmd = fmt.Sprintf(`%s/pf9/installer.sh --proxy %s --skip-os-check --no-ntp`, homeDir, ctx.ProxyURL)
} else {
cmd = fmt.Sprintf(`%s/pf9/installer.sh --no-proxy --skip-os-check --no-ntp`, homeDir)
}

installOptions := fmt.Sprintf("--insecure --project-name=%s 2>&1 | tee -a %s/pf9/agent_install", auth.ProjectID, homeDir)

if IsRemoteExecutor {
cmd = fmt.Sprintf(`bash %s %s`, cmd, installOptions)
_, err = exec.RunWithStdout(cmd)
} else {
cmd = fmt.Sprintf(`%s %s`, cmd, installOptions)
_, err = exec.RunWithStdout("bash", "-c", cmd)
}
return err
}

removeTempDirAndInstaller(exec)

func downloadLegacyInstaller(regionURL string, auth keystone.KeystoneAuth, hostOS string, exec cmdexec.Executor) error {
url := fmt.Sprintf("https://%s/private/platform9-install-%s.sh", regionURL, hostOS)
//use insecure by default
cmd := fmt.Sprintf(`curl --insecure --silent --show-error -H 'X-Auth-Token:%s' %s -o %s/pf9/installer.sh`, auth.Token, url, homeDir)
_, err := exec.RunWithStdout("bash", "-c", cmd)
if err != nil {
_, exitCode := cmdexec.ExitCodeChecker(err)
fmt.Printf("\n")
zap.S().Debugf("Error:%s", util.InstallerErrors[exitCode])
fmt.Println("Error :", util.InstallerErrors[exitCode])
return fmt.Errorf("error while running installer script: %s", util.InstallerErrors[exitCode])
return err
}

// TODO: here we actually need additional validation by checking /tmp/agent_install. log
zap.S().Debug("Hostagent installed successfully")
zap.S().Debug("Hostagent download completed successfully")
return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/util/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var ProcessesList []string // Kubernetes clusters processes list
var SwapOffDisabled bool // If this is true the swapOff functionality will be disabled.
var SkipPrepNode bool
var CheckIfOnboarded bool
var SkipInstallerDownload bool

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