Skip to content

Commit

Permalink
Use CLI to validate minimal RBAC tests instead of testim (#4126)
Browse files Browse the repository at this point in the history
* Use CLI to validate minimal RBAC tests instead of testim
  • Loading branch information
sgalsaleh authored Nov 9, 2023
1 parent 5ad37c5 commit 8df2257
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 92 deletions.
256 changes: 198 additions & 58 deletions .github/workflows/build-test.yaml

Large diffs are not rendered by default.

33 changes: 26 additions & 7 deletions cmd/kots/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/replicatedhq/kots/pkg/kurl"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/metrics"
preflighttypes "github.com/replicatedhq/kots/pkg/preflight/types"
"github.com/replicatedhq/kots/pkg/print"
"github.com/replicatedhq/kots/pkg/pull"
"github.com/replicatedhq/kots/pkg/replicatedapp"
Expand Down Expand Up @@ -447,14 +448,14 @@ func InstallCmd() *cobra.Command {
log.FinishSpinner()

switch status {
case storetypes.VersionPendingPreflight:
case storetypes.VersionPendingPreflight, storetypes.VersionPending:
log.ActionWithSpinner("Waiting for preflight checks to complete")
if err := ValidatePreflightStatus(deployOptions, authSlug, apiEndpoint); err != nil {
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)
print.PreflightResults(perr.Results)
cmd.SilenceErrors = true // Stop Cobra from printing the error, we format the message ourselves
} else {
log.FinishSpinnerWithError()
Expand Down Expand Up @@ -1020,7 +1021,7 @@ func checkPreflightsComplete(response *handlers.GetPreflightResultResponse) (boo

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

func (e preflightError) Error() string {
Expand All @@ -1034,12 +1035,30 @@ func checkPreflightResults(response *handlers.GetPreflightResultResponse) (bool,
return false, nil
}

var results preflight.UploadPreflightResults
var results preflighttypes.PreflightResults
err := json.Unmarshal([]byte(response.PreflightResult.Result), &results)
if err != nil {
return false, errors.Wrap(err, fmt.Sprintf("failed to unmarshal upload preflight results from response: %v", response.PreflightResult.Result))
}

if len(results.Errors) > 0 {
isRBAC := false
for _, err := range results.Errors {
if err.IsRBAC {
isRBAC = true
break
}
}
msg := "There are preflight check errors for the application. The app was not deployed."
if isRBAC {
msg = "The Kubernetes RBAC policy that the Admin Console is running with does not have access to complete the Preflight Checks. It's recommended that you run these manually before proceeding. The app was not deployed."
}
return false, preflightError{
Msg: msg,
Results: results,
}
}

var isWarn, isFail bool
for _, result := range results.Results {
if result.IsWarn {
Expand All @@ -1053,20 +1072,20 @@ func checkPreflightResults(response *handlers.GetPreflightResultResponse) (bool,
if isWarn && isFail {
return false, preflightError{
Msg: "There are preflight check failures and warnings for the application. The app was not deployed.",
Results: results.Results,
Results: results,
}
}

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

Expand Down
1 change: 0 additions & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ var _ = Describe("E2E", func() {
Entry(nil, inventory.NewSmokeTest()),
Entry(nil, inventory.NewAirgapSmokeTest()),
Entry(nil, inventory.NewConfigValidation()),
Entry(nil, inventory.NewMinimalRBACTest()),
Entry(nil, inventory.NewBackupAndRestore()),
Entry(nil, inventory.NewNoRequiredConfig()),
Entry(nil, inventory.NewVersionHistoryPagination()),
Expand Down
9 changes: 0 additions & 9 deletions e2e/testim/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ func NewConfigValidation() Test {
}
}

func NewMinimalRBACTest() Test {
return Test{
Name: "Minimal RBAC",
Suite: "minimal-rbac",
Namespace: "minimal-rbac",
UpstreamURI: "minimal-rbac/automated",
}
}

func NewBackupAndRestore() Test {
return Test{
Name: "Backup and Restore",
Expand Down
2 changes: 1 addition & 1 deletion hack/build-ttl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ printf "\n\n\n"
printf "Run command: ${GREEN}kubectl edit deployment kotsadm${NC}\n"
printf "Replace image with: ${GREEN}ttl.sh/${CURRENT_USER}/kotsadm:24h${NC}\n"
printf "\n"
printf "These images are good for 12 hours\n"
printf "These images are good for 24 hours\n"
2 changes: 1 addition & 1 deletion migrations/build-ttl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ printf "\n\n\n"
printf "Run command: ${GREEN}kubectl edit deployment kotsadm${NC}\n"
printf "Replace image with: ${GREEN}${IMAGE}${NC}\n"
printf "\n"
printf "This image is good for 12 hours\n"
printf "This image is good for 24 hours\n"
4 changes: 4 additions & 0 deletions pkg/preflight/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/pkg/errors"
apptypes "github.com/replicatedhq/kots/pkg/app/types"
Expand Down Expand Up @@ -277,6 +278,9 @@ func maybeDeployFirstVersion(appID string, sequence int64, preflightResults *typ
return false, errors.Wrap(err, "failed to deploy version")
}

// this ensures the version status is updated before returning
time.Sleep(time.Second)

return true, nil
}

Expand Down
15 changes: 0 additions & 15 deletions pkg/print/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (

configtypes "github.com/replicatedhq/kots/pkg/kotsadmconfig/types"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/preflight"
tsPreflight "github.com/replicatedhq/troubleshoot/pkg/preflight"
)

func ConfigValidationErrors(log *logger.CLILogger, groupValidationErrors []configtypes.ConfigGroupValidationError) {
Expand All @@ -28,16 +26,3 @@ func ConfigValidationErrors(log *logger.CLILogger, groupValidationErrors []confi
log.FinishSpinnerWithError()
log.Errorf(sb.String())
}

func PreflightErrors(log *logger.CLILogger, results []*tsPreflight.UploadPreflightResult) {
w := NewTabWriter()
defer w.Flush()

fmt.Fprintf(w, "\n")
fmtColumns := "%s\t%s\t%s\n"
fmt.Fprintf(w, fmtColumns, "STATE", "TITLE", "MESSAGE")
for _, result := range results {
fmt.Fprintf(w, fmtColumns, strings.ToUpper(preflight.GetPreflightCheckState(result)), result.Title, result.Message)
}
fmt.Fprintf(w, "\n")
}
33 changes: 33 additions & 0 deletions pkg/print/preflight.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package print

import (
"fmt"
"strings"

"github.com/replicatedhq/kots/pkg/preflight"
preflighttypes "github.com/replicatedhq/kots/pkg/preflight/types"
)

func PreflightResults(results preflighttypes.PreflightResults) {
w := NewTabWriter()
defer w.Flush()

if len(results.Errors) > 0 {
fmt.Fprintf(w, "\n")
for _, err := range results.Errors {
fmtColumns := " - %s\n"
fmt.Fprintf(w, fmtColumns, err.Error)
}
fmt.Fprintf(w, "\n")
}

if len(results.Results) > 0 {
fmt.Fprintf(w, "\n")
fmtColumns := "%s\t%s\t%s\n"
fmt.Fprintf(w, fmtColumns, "STATE", "TITLE", "MESSAGE")
for _, result := range results.Results {
fmt.Fprintf(w, fmtColumns, strings.ToUpper(preflight.GetPreflightCheckState(result)), result.Title, result.Message)
}
fmt.Fprintf(w, "\n")
}
}

0 comments on commit 8df2257

Please sign in to comment.