Skip to content

Commit

Permalink
Merge pull request #135 from reetasingh/fix/recreate
Browse files Browse the repository at this point in the history
Throw fatal error and ask user to run cleanup when a k8s resource already exists in the cluster
  • Loading branch information
k8s-ci-robot authored Jan 29, 2024
2 parents 9669087 + d9c9e70 commit cd71d67
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func RunE2E(clientset *kubernetes.Clientset) {
ns, err := clientset.CoreV1().Namespaces().Create(ctx, &conformanceNS, metav1.CreateOptions{})
if err != nil {
if errors.IsAlreadyExists(err) {
log.Printf("namespace already exist %s", common.PodName)
log.Fatalf("namespace already exist %s. Please run cleanup first", conformanceNS.ObjectMeta.Name)
} else {
log.Fatal(err)
}
Expand All @@ -221,7 +221,7 @@ func RunE2E(clientset *kubernetes.Clientset) {
sa, err := clientset.CoreV1().ServiceAccounts(ns.Name).Create(ctx, &conformanceSA, metav1.CreateOptions{})
if err != nil {
if errors.IsAlreadyExists(err) {
log.Printf("serviceaccount already exist %s", common.PodName)
log.Fatalf("serviceaccount already exist %s. Please run cleanup first", conformanceSA.ObjectMeta.Name)
} else {
log.Fatal(err)
}
Expand All @@ -231,7 +231,7 @@ func RunE2E(clientset *kubernetes.Clientset) {
clusterRole, err := clientset.RbacV1().ClusterRoles().Create(ctx, &conformanceClusterRole, metav1.CreateOptions{})
if err != nil {
if errors.IsAlreadyExists(err) {
log.Printf("clusterrole already exist %s", common.PodName)
log.Printf("clusterrole already exist %s", conformanceClusterRole.ObjectMeta.Name)
} else {
log.Fatal(err)
}
Expand All @@ -241,7 +241,7 @@ func RunE2E(clientset *kubernetes.Clientset) {
clusterRoleBinding, err := clientset.RbacV1().ClusterRoleBindings().Create(ctx, &conformanceClusterRoleBinding, metav1.CreateOptions{})
if err != nil {
if errors.IsAlreadyExists(err) {
log.Printf("clusterrolebinding already exist %s", common.PodName)
log.Printf("clusterrolebinding already exist %s", conformanceClusterRoleBinding.ObjectMeta.Name)
} else {
log.Fatal(err)
}
Expand Down Expand Up @@ -287,10 +287,10 @@ func RunE2E(clientset *kubernetes.Clientset) {
Value: "/tmp/repo-list/repo-list.yaml",
})

cm, err := clientset.CoreV1().ConfigMaps(common.Namespace).Create(ctx, configMap, metav1.CreateOptions{})
cm, err := clientset.CoreV1().ConfigMaps(ns.Name).Create(ctx, configMap, metav1.CreateOptions{})
if err != nil {
if errors.IsAlreadyExists(err) {
log.Printf("configmap already exists %s", configMap.ObjectMeta.Name)
log.Fatalf("configmap already exists %s. Please run cleanup first", configMap.ObjectMeta.Name)
} else {
log.Fatal(err)
}
Expand All @@ -308,7 +308,7 @@ func RunE2E(clientset *kubernetes.Clientset) {
pod, err := clientset.CoreV1().Pods(ns.Name).Create(ctx, &conformancePod, metav1.CreateOptions{})
if err != nil {
if errors.IsAlreadyExists(err) {
log.Printf("pod already exist %s", common.PodName)
log.Fatalf("pod already exist %s. Please run cleanup first", conformancePod.ObjectMeta.Name)
} else {
log.Fatal(err)
}
Expand Down

0 comments on commit cd71d67

Please sign in to comment.