Skip to content

Commit

Permalink
Merge branch 'main' into cbo/test-latest-cmx-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig O'Donnell authored Oct 11, 2023
2 parents e01e9d2 + 247b299 commit 82dd3ae
Show file tree
Hide file tree
Showing 81 changed files with 4,321 additions and 442 deletions.
57 changes: 45 additions & 12 deletions cmd/kots/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
Expand All @@ -33,6 +32,7 @@ import (
"github.com/replicatedhq/kots/pkg/kurl"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/metrics"
"github.com/replicatedhq/kots/pkg/print"
"github.com/replicatedhq/kots/pkg/pull"
"github.com/replicatedhq/kots/pkg/replicatedapp"
"github.com/replicatedhq/kots/pkg/store/kotsstore"
Expand All @@ -47,6 +47,10 @@ import (
"k8s.io/client-go/kubernetes"
)

var client = &http.Client{
Timeout: time.Second * 30,
}

func InstallCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "install [upstream uri]",
Expand Down Expand Up @@ -321,7 +325,7 @@ func InstallCmd() *cobra.Command {

log.ActionWithoutSpinner("Extracting airgap bundle")

airgapRootDir, err := ioutil.TempDir("", "kotsadm-airgap")
airgapRootDir, err := os.MkdirTemp("", "kotsadm-airgap")
if err != nil {
return errors.Wrap(err, "failed to create temp dir")
}
Expand Down Expand Up @@ -426,6 +430,7 @@ func InstallCmd() *cobra.Command {
case err := <-errChan:
if err != nil {
log.Error(err)
// TODO: Why is this a negative exit code?
os.Exit(-1)
}
case <-stopCh:
Expand All @@ -445,8 +450,16 @@ func InstallCmd() *cobra.Command {
case storetypes.VersionPendingPreflight:
log.ActionWithSpinner("Waiting for preflight checks to complete")
if err := ValidatePreflightStatus(deployOptions, authSlug, apiEndpoint); err != nil {
log.FinishSpinnerWithError()
return errors.Wrap(err, "failed to validate preflight results")
perr := preflightError{}
if errors.As(err, &perr) {
log.FinishSpinner() // We succeeded waiting for the results. Don't finish with an error
log.Errorf(perr.Msg)
print.PreflightErrors(log, perr.Results)
cmd.SilenceErrors = true // Stop Cobra from printing the error, we format the message ourselves
} else {
log.FinishSpinnerWithError()
}
return err
}
log.FinishSpinner()
case storetypes.VersionPendingConfig:
Expand Down Expand Up @@ -692,7 +705,7 @@ func getIngressConfig(v *viper.Viper) (*kotsv1beta1.IngressConfig, error) {

ingressConfig := kotsv1beta1.IngressConfig{}
if ingressConfigPath != "" {
content, err := ioutil.ReadFile(ingressConfigPath)
content, err := os.ReadFile(ingressConfigPath)
if err != nil {
return nil, errors.Wrap(err, "failed to read ingress service config file")
}
Expand All @@ -719,7 +732,7 @@ func getIdentityConfig(v *viper.Viper) (*kotsv1beta1.IdentityConfig, error) {

identityConfig := kotsv1beta1.IdentityConfig{}
if identityConfigPath != "" {
content, err := ioutil.ReadFile(identityConfigPath)
content, err := os.ReadFile(identityConfigPath)
if err != nil {
return nil, errors.Wrap(err, "failed to read identity service config file")
}
Expand Down Expand Up @@ -910,7 +923,7 @@ func getAutomatedInstallStatus(url string, authSlug string) (*kotsstore.TaskStat
return nil, errors.Errorf("unexpected status code %d", resp.StatusCode)
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, errors.Wrap(err, "failed to read response body")
}
Expand Down Expand Up @@ -964,7 +977,7 @@ func getPreflightResponse(url string, authSlug string) (*handlers.GetPreflightRe
newReq.Header.Add("Content-Type", "application/json")
newReq.Header.Add("Authorization", authSlug)

resp, err := http.DefaultClient.Do(newReq)
resp, err := client.Do(newReq)
if err != nil {
return nil, errors.Wrap(err, "failed to execute request")
}
Expand All @@ -974,7 +987,7 @@ func getPreflightResponse(url string, authSlug string) (*handlers.GetPreflightRe
return nil, errors.Errorf("unexpected status code %d", resp.StatusCode)
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, errors.Wrap(err, "failed to read response body")
}
Expand Down Expand Up @@ -1005,6 +1018,17 @@ func checkPreflightsComplete(response *handlers.GetPreflightResultResponse) (boo
return true, nil
}

type preflightError struct {
Msg string
Results []*preflight.UploadPreflightResult
}

func (e preflightError) Error() string {
return e.Msg
}

func (e preflightError) Unwrap() error { return fmt.Errorf(e.Msg) }

func checkPreflightResults(response *handlers.GetPreflightResultResponse) (bool, error) {
if response.PreflightResult.Result == "" {
return false, nil
Expand All @@ -1027,14 +1051,23 @@ func checkPreflightResults(response *handlers.GetPreflightResultResponse) (bool,
}

if isWarn && isFail {
return false, errors.New("There are preflight check failures and warnings for the application. The app was not deployed.")
return false, preflightError{
Msg: "There are preflight check failures and warnings for the application. The app was not deployed.",
Results: results.Results,
}
}

if isWarn {
return false, errors.New("There are preflight check warnings for the application. The app was not deployed.")
return false, preflightError{
Msg: "There are preflight check warnings for the application. The app was not deployed.",
Results: results.Results,
}
}
if isFail {
return false, errors.New("There are preflight check failures for the application. The app was not deployed.")
return false, preflightError{
Msg: "There are preflight check failures for the application. The app was not deployed.",
Results: results.Results,
}
}

return true, nil
Expand Down
8 changes: 4 additions & 4 deletions cmd/kots/cli/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ var _ = Describe("Install", func() {
})

It("returns an error if the preflight collection results cannot be parsed", func() {
invalidPreflightCollection, err := json.Marshal(handlers.GetPreflightResultResponse{
invalidPreflightCollection, _ := json.Marshal(handlers.GetPreflightResultResponse{
PreflightProgress: `{invalid: json}`,
PreflightResult: preflighttypes.PreflightResult{},
})
Expand All @@ -239,13 +239,13 @@ var _ = Describe("Install", func() {
),
)

err = ValidatePreflightStatus(validDeployOptions, authSlug, server.URL())
err := ValidatePreflightStatus(validDeployOptions, authSlug, server.URL())
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("failed to unmarshal collect progress for preflights"))
})

It("returns an error if the upload preflight results are invalid", func() {
invalidUploadPreflightResponse, err := json.Marshal(handlers.GetPreflightResultResponse{
invalidUploadPreflightResponse, _ := json.Marshal(handlers.GetPreflightResultResponse{
PreflightProgress: "",
PreflightResult: preflighttypes.PreflightResult{
Result: "{invalid: json}",
Expand All @@ -262,7 +262,7 @@ var _ = Describe("Install", func() {
),
)

err = ValidatePreflightStatus(validDeployOptions, authSlug, server.URL())
err := ValidatePreflightStatus(validDeployOptions, authSlug, server.URL())
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("failed to unmarshal upload preflight results"))
})
Expand Down
3 changes: 2 additions & 1 deletion cmd/kots/cli/set-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -127,7 +128,7 @@ func SetConfigCmd() *cobra.Command {
}
defer resp.Body.Close()

respBody, err := ioutil.ReadAll(resp.Body)
respBody, err := io.ReadAll(resp.Body)
if err != nil {
log.FinishSpinnerWithError()
return errors.Wrap(err, "failed to read server response")
Expand Down
28 changes: 14 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ require (
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0
github.com/replicatedhq/kotskinds v0.0.0-20230724164735-f83482cc9cfe
github.com/replicatedhq/kotskinds v0.0.0-20231004174055-e6676d808a82
github.com/replicatedhq/kurlkinds v1.3.6
github.com/replicatedhq/troubleshoot v0.72.1
github.com/replicatedhq/troubleshoot v0.74.0
github.com/replicatedhq/yaml/v3 v3.0.0-beta5-replicatedhq
github.com/robfig/cron v1.2.0
github.com/robfig/cron/v3 v3.0.1
Expand All @@ -74,16 +74,16 @@ require (
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
helm.sh/helm/v3 v3.12.3
k8s.io/api v0.28.1
k8s.io/apimachinery v0.28.1
k8s.io/cli-runtime v0.28.1
k8s.io/client-go v0.28.1
k8s.io/api v0.28.2
k8s.io/apimachinery v0.28.2
k8s.io/cli-runtime v0.28.2
k8s.io/client-go v0.28.2
k8s.io/cluster-bootstrap v0.23.6
k8s.io/helm v2.14.3+incompatible
k8s.io/kubelet v0.23.6
k8s.io/utils v0.0.0-20230505201702-9f6742963106
sigs.k8s.io/application v0.8.3
sigs.k8s.io/controller-runtime v0.16.1
sigs.k8s.io/controller-runtime v0.16.2
sigs.k8s.io/kustomize/api v0.14.0
sigs.k8s.io/kustomize/kyaml v0.14.3
sigs.k8s.io/yaml v1.3.0
Expand Down Expand Up @@ -320,7 +320,7 @@ require (
github.com/rubenv/sql-migrate v1.3.1 // indirect
github.com/russellhaering/goxmldsig v1.3.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil/v3 v3.23.8 // indirect
github.com/shirou/gopsutil/v3 v3.23.9 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sigstore/fulcio v1.2.0 // indirect
github.com/sigstore/rekor v1.2.0 // indirect
Expand Down Expand Up @@ -355,15 +355,15 @@ require (
go.mongodb.org/mongo-driver v1.11.3 // indirect
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.17.0 // indirect
go.opentelemetry.io/otel/metric v1.17.0 // indirect
go.opentelemetry.io/otel/sdk v1.17.0 // indirect
go.opentelemetry.io/otel/trace v1.17.0 // indirect
go.opentelemetry.io/otel v1.18.0 // indirect
go.opentelemetry.io/otel/metric v1.18.0 // indirect
go.opentelemetry.io/otel/sdk v1.18.0 // indirect
go.opentelemetry.io/otel/trace v1.18.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
Expand All @@ -387,7 +387,7 @@ require (
k8s.io/kube-aggregator v0.19.12 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/kubectl v0.28.1 // indirect
k8s.io/metrics v0.28.1 // indirect
k8s.io/metrics v0.28.2 // indirect
oras.land/oras-go v1.2.3 // indirect
periph.io/x/host/v3 v3.8.2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
Loading

0 comments on commit 82dd3ae

Please sign in to comment.