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

Refactoring constants for skip validations #6190

Merged
merged 2 commits into from
Jul 17, 2023
Merged
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
7 changes: 1 addition & 6 deletions pkg/validations/createvalidations/createvalidations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import (
"github.com/aws/eks-anywhere/pkg/validations"
)

// string values of supported validation names that can be skipped.
const (
VSphereUserPriv = "vsphere-user-privilege"
)

// SkippableValidations represents all the validations we offer for users to skip.
var SkippableValidations = []string{
VSphereUserPriv,
validations.VSphereUserPriv,
}

func New(opts *validations.Opts) *CreateValidations {
Expand Down
6 changes: 6 additions & 0 deletions pkg/validations/skipvalidations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import (
"strings"
)

// string values of supported validation names that can be skipped.
const (
PDB = "pod-disruption"
VSphereUserPriv = "vsphere-user-privilege"
)

// ValidSkippableValidationsMap returns a map for all valid skippable validations as keys, defaulting values to false.
// Defaulting to False means these validations won't be skipped unless set to True.
func validSkippableValidationsMap(skippableValidations []string) map[string]bool {
Expand Down
15 changes: 8 additions & 7 deletions pkg/validations/skipvalidations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,26 @@ func TestValidateSkippableValidation(t *testing.T) {
want: nil,
wantErr: fmt.Errorf("invalid validation name to be skipped. The supported validations that can be skipped using --skip-validations are %s", strings.Join(upgradevalidations.SkippableValidations[:], ",")),
skippedValidations: []string{"test"},
skippableValidations: []string{upgradevalidations.PDB},
skippableValidations: upgradevalidations.SkippableValidations,
},
{
name: "valid upgrade validation param",
want: map[string]bool{
upgradevalidations.PDB: true,
validations.PDB: true,
validations.VSphereUserPriv: false,
},
wantErr: nil,
skippedValidations: []string{upgradevalidations.PDB},
skippableValidations: []string{upgradevalidations.PDB},
skippedValidations: []string{validations.PDB},
skippableValidations: upgradevalidations.SkippableValidations,
},
{
name: "valid create validation param",
want: map[string]bool{
createvalidations.VSphereUserPriv: true,
validations.VSphereUserPriv: true,
},
wantErr: nil,
skippedValidations: []string{createvalidations.VSphereUserPriv},
skippableValidations: []string{createvalidations.VSphereUserPriv},
skippedValidations: []string{validations.VSphereUserPriv},
skippableValidations: createvalidations.SkippableValidations,
},
}
for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion pkg/validations/upgradevalidations/poddisruptionbudgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func ValidatePodDisruptionBudgets(ctx context.Context, k validations.KubectlClie
}

if len(podDisruptionBudgets.Items) != 0 {
return fmt.Errorf("one or more pod disruption budgets were detected on the cluster. Use the --skip-validations=%s flag if you wish to skip the validations for pod disruption budgets and proceed with the upgrade operation", PDB)
return fmt.Errorf("one or more pod disruption budgets were detected on the cluster. Use the --skip-validations=%s flag if you wish to skip the validations for pod disruption budgets and proceed with the upgrade operation", validations.PDB)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestValidatePodDisruptionBudgets(t *testing.T) {
},
},
},
wantErr: fmt.Errorf("one or more pod disruption budgets were detected on the cluster. Use the --skip-validations=%s flag if you wish to skip the validations for pod disruption budgets and proceed with the upgrade operation", upgradevalidations.PDB),
wantErr: fmt.Errorf("one or more pod disruption budgets were detected on the cluster. Use the --skip-validations=%s flag if you wish to skip the validations for pod disruption budgets and proceed with the upgrade operation", validations.PDB),
},
{
name: "PDBs don't exist on cluster",
Expand Down
2 changes: 1 addition & 1 deletion pkg/validations/upgradevalidations/preflightvalidations.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (u *UpgradeValidations) PreflightValidations(ctx context.Context) []validat
})
}

if !u.Opts.SkippedValidations[PDB] {
if !u.Opts.SkippedValidations[validations.PDB] {
upgradeValidations = append(
upgradeValidations,
func() *validations.ValidationResult {
Expand Down
8 changes: 2 additions & 6 deletions pkg/validations/upgradevalidations/upgradevalidations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ import (
"github.com/aws/eks-anywhere/pkg/validations"
)

// string values of supported validation names that can be skipped.
const (
PDB = "pod-disruption"
)

// SkippableValidations represents all the validations we offer for users to skip.
var SkippableValidations = []string{
PDB,
validations.PDB,
validations.VSphereUserPriv,
}

func New(opts *validations.Opts) *UpgradeValidations {
Expand Down