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

Add skip preflight check flag #212

Open
wants to merge 1 commit into
base: main
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
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
runListImages bool
runConformance bool
continueConformance bool
skipPreflight string
conformanceFocus string
)

Expand Down Expand Up @@ -74,6 +75,7 @@ func New() *cobra.Command {
rootCmd.Flags().BoolVar(&runCleanup, "cleanup", false, "cleanup resources (pods, namespaces etc).")
rootCmd.Flags().BoolVar(&runListImages, "list-images", false, "list all images that will be used during conformance tests.")
rootCmd.Flags().BoolVar(&runConformance, "conformance", false, "run conformance tests.")
rootCmd.Flags().StringVar(&skipPreflight, "skip-preflight", "", "skip namespace check, use the specified namespace.")
rootCmd.Flags().BoolVar(&continueConformance, "continue", false, "connect to an already running conformance test pod.")
rootCmd.Flags().StringVar(&conformanceFocus, "focus", "", "focus runs a specific e2e test. e.g. - sig-auth. allows regular expressions.")

Expand Down Expand Up @@ -147,7 +149,7 @@ func action(ctx context.Context, config *types.Configuration) error {
if continueConformance {
log.Println("Attempting to continue with already running tests...")
} else {
if err := testRunner.Deploy(ctx, conformanceFocus, verboseGinkgo, config.StartupTimeout); err != nil {
if err := testRunner.Deploy(ctx, conformanceFocus, skipPreflight, verboseGinkgo, config.StartupTimeout); err != nil {
return fmt.Errorf("failed to deploy tests: %w", err)
}
}
Expand Down
78 changes: 52 additions & 26 deletions pkg/conformance/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

// Deploy sets up the necessary resources and runs E2E conformance tests.
func (r *TestRunner) Deploy(ctx context.Context, focus string, verboseGinkgo bool, timeout time.Duration) error {
func (r *TestRunner) Deploy(ctx context.Context, focus, skipPreflight string, verboseGinkgo bool, timeout time.Duration) error {
conformanceNS := corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: r.config.Namespace,
Expand Down Expand Up @@ -195,46 +195,66 @@ func (r *TestRunner) Deploy(ctx context.Context, focus string, verboseGinkgo boo
ns, err := r.clientset.CoreV1().Namespaces().Create(ctx, &conformanceNS, metav1.CreateOptions{})
if err != nil {
if errors.IsAlreadyExists(err) {
//nolint:stylecheck // error message references a Kubernetes resource type.
err = fmt.Errorf("Namespace %s already exist, please run --cleanup first", conformanceNS.Name)
if skipPreflight != "" {
log.Printf("Using existing namespace: %s", r.config.Namespace)
} else {
//nolint:stylecheck // error message references a Kubernetes resource type.
return fmt.Errorf("namespace %s already exists, please run with --cleanup first", conformanceNS.Name)
}
} else {
return fmt.Errorf("failed to create namespace: %w", err)
}

return err
} else {
log.Printf("Created namespace %s.", ns.Name)
}
log.Printf("Created Namespace %s.", ns.Name)

sa, err := r.clientset.CoreV1().ServiceAccounts(ns.Name).Create(ctx, &conformanceSA, metav1.CreateOptions{})
sa, err := r.clientset.CoreV1().ServiceAccounts(r.config.Namespace).Create(ctx, &conformanceSA, metav1.CreateOptions{})
if err != nil {
if errors.IsAlreadyExists(err) {
//nolint:stylecheck // error message references a Kubernetes resource type.
err = fmt.Errorf("ServiceAccount %s already exist, please run --cleanup first", conformanceSA.Name)
if skipPreflight != "" {
log.Printf("using existing ServiceAccount: %s/%s", r.config.Namespace, ServiceAccountName)
} else {
//nolint:stylecheck // error message references a Kubernetes resource type.
return fmt.Errorf("ServiceAccount %s already exist, please run --cleanup first", conformanceSA.Name)
}
} else {
return fmt.Errorf("failed to create ServiceAccount: %w", err)
}

return err
} else {
log.Printf("Created ServiceAccount %s.", sa.Name)
}
log.Printf("Created ServiceAccount %s.", sa.Name)

clusterRole, err := r.clientset.RbacV1().ClusterRoles().Create(ctx, &conformanceClusterRole, metav1.CreateOptions{})
if err != nil {
if errors.IsAlreadyExists(err) {
//nolint:stylecheck // error message references a Kubernetes resource type.
err = fmt.Errorf("ClusterRole %s already exist, please run --cleanup first", conformanceClusterRole.Name)
if skipPreflight != "" {
log.Printf("using existing ClusterRole: %s/%s", r.config.Namespace, r.namespacedName(ClusterRoleName))
} else {
//nolint:stylecheck // error message references a Kubernetes resource type.
return fmt.Errorf("ClusterRole %s already exist, please run --cleanup first", conformanceClusterRole.Name)
}
} else {
return fmt.Errorf("failed to create ClusterRole: %w", err)
}

return err
} else {
log.Printf("Created ClusterRole %s.", clusterRole.Name)
}
log.Printf("Created Clusterrole %s.", clusterRole.Name)

clusterRoleBinding, err := r.clientset.RbacV1().ClusterRoleBindings().Create(ctx, &conformanceClusterRoleBinding, metav1.CreateOptions{})
if err != nil {
if errors.IsAlreadyExists(err) {
//nolint:stylecheck // error message references a Kubernetes resource type.
err = fmt.Errorf("ClusterRoleBinding %s already exist, please run --cleanup first", conformanceClusterRoleBinding.Name)
if skipPreflight != "" {
log.Printf("using existing ClusterRoleBinding: %s/%s", r.config.Namespace, r.namespacedName(ClusterRoleBindingName))
} else {
//nolint:stylecheck // error message references a Kubernetes resource type.
return fmt.Errorf("ClusterRoleBinding %s already exist, please run --cleanup first", conformanceClusterRoleBinding.Name)
}
} else {
return fmt.Errorf("failed to create ClusterRoleBinding: %w", err)
}

return err
} else {
log.Printf("Created ClusterRoleBinding %s.", clusterRoleBinding.Name)
}
log.Printf("Created ClusterRoleBinding %s.", clusterRoleBinding.Name)

if filename := r.config.TestRepoList; filename != "" {
repoListData, err := os.ReadFile(filename)
Expand Down Expand Up @@ -298,11 +318,17 @@ func (r *TestRunner) Deploy(ctx context.Context, focus string, verboseGinkgo boo
pod, err := common.CreatePod(ctx, r.clientset, &conformancePod, timeout)
if err != nil {
if errors.IsAlreadyExists(err) {
//nolint:stylecheck // error message references a Kubernetes resource type.
err = fmt.Errorf("Pod %s already exist, please run --cleanup first", pod.Name)
if skipPreflight != "" {
log.Printf("using existing Pod: %s/%s", r.config.Namespace, "e2e-conformance-test")
} else {
//nolint:stylecheck // error message references a Kubernetes resource type.
return fmt.Errorf("Pod %s already exist, please run --cleanup first", conformanceClusterRoleBinding.Name)
}
} else {
return fmt.Errorf("failed to create Pod: %w", err)
}

return err
} else {
log.Printf("Created ConformancePod %s.", pod.Name)
}

return nil
Expand Down