github.com/verrazzano/verrazzano@v1.7.0/pkg/namespace/namespace.go (about) 1 // Copyright (c) 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package namespace 5 6 import ( 7 "context" 8 "fmt" 9 "github.com/verrazzano/verrazzano/pkg/k8sutil" 10 "github.com/verrazzano/verrazzano/platform-operator/constants" 11 "k8s.io/apimachinery/pkg/api/errors" 12 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 13 ) 14 15 // CheckIfVerrazzanoManagedNamespaceExists returns true if the namespace exists and has the verrazzano.io/namespace label 16 func CheckIfVerrazzanoManagedNamespaceExists(nsName string) (bool, error) { 17 client, err := k8sutil.GetCoreV1Func() 18 if err != nil { 19 return false, fmt.Errorf("Failure creating corev1 client: %v", err) 20 } 21 22 namespace, err := client.Namespaces().Get(context.TODO(), nsName, metav1.GetOptions{}) 23 if err != nil && !errors.IsNotFound(err) { 24 return false, fmt.Errorf("Unexpected error checking for namespace %s: %v", nsName, err) 25 } 26 if namespace == nil || namespace.Labels[constants.VerrazzanoManagedKey] == "" { 27 return false, nil 28 } 29 return true, nil 30 }