...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/test/controller/reconcile.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/test/controller

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package controller
    16  
    17  import (
    18  	"context"
    19  	"log"
    20  
    21  	"github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/k8s"
    22  
    23  	corev1 "k8s.io/api/core/v1"
    24  	"k8s.io/apimachinery/pkg/api/errors"
    25  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    26  	"sigs.k8s.io/controller-runtime/pkg/client"
    27  )
    28  
    29  func EnsureNamespaceExists(c client.Client, name string) {
    30  	ns := &corev1.Namespace{}
    31  	ns.SetName(name)
    32  	if err := c.Create(context.Background(), ns); err != nil {
    33  		if !errors.IsAlreadyExists(err) {
    34  			log.Fatalf("error creating namespace %v: %v", name, err)
    35  		}
    36  	}
    37  }
    38  
    39  func HasOperatorFinalizer(o metav1.Object) bool {
    40  	for _, f := range o.GetFinalizers() {
    41  		if f == k8s.OperatorFinalizer {
    42  			return true
    43  		}
    44  	}
    45  	return false
    46  }
    47  

View as plain text