Skip to content

Commit

Permalink
Merge pull request #212 from aniruddha2000/ani/issues/211
Browse files Browse the repository at this point in the history
Add skip preflight check flag
  • Loading branch information
k8s-ci-robot authored Feb 7, 2025
2 parents 6af6139 + d67f42c commit 663d6f7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 27 deletions.
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 @@ -35,7 +35,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 @@ -223,46 +223,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 @@ -326,11 +346,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

0 comments on commit 663d6f7

Please sign in to comment.