...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s/constants.go

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

     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 k8s
    16  
    17  import (
    18  	"fmt"
    19  	"time"
    20  
    21  	"k8s.io/apimachinery/pkg/types"
    22  )
    23  
    24  type ManagementConflictPreventionPolicy string
    25  
    26  // TODO: clean up old conditions used in handcrafted controllers
    27  const (
    28  	CNRMGroup                            = "cnrm.cloud.google.com"
    29  	ApiDomainSuffix                      = ".cnrm.cloud.google.com"
    30  	SystemNamespace                      = "cnrm-system"
    31  	ControllerManagerNamePrefix          = "cnrm-controller-manager"
    32  	ControllerMaxConcurrentReconciles    = 20
    33  	ReconcileDeadline                    = 59 * time.Minute
    34  	TimeToLeaseExpiration                = 40 * time.Minute
    35  	TimeToLeaseRenewal                   = 20 * time.Minute
    36  	MeanReconcileReenqueuePeriod         = 10 * time.Minute
    37  	JitterFactor                         = 2.0
    38  	UpToDate                             = "UpToDate"
    39  	UpToDateMessage                      = "The resource is up to date"
    40  	Created                              = "Created"
    41  	CreatedMessage                       = "Successfully created"
    42  	CreateFailed                         = "CreateFailed"
    43  	CreateFailedMessageTmpl              = "Create call failed: %v"
    44  	Updating                             = "Updating"
    45  	UpdatingMessage                      = "Update in progress"
    46  	UpdateFailed                         = "UpdateFailed"
    47  	Deleting                             = "Deleting"
    48  	DeletingMessage                      = "Deletion in progress"
    49  	Deleted                              = "Deleted"
    50  	DeletedMessage                       = "Successfully deleted"
    51  	DeleteFailed                         = "DeleteFailed"
    52  	NoCondition                          = "NoCondition"
    53  	DeleteFailedMessageTmpl              = "Delete call failed: %v"
    54  	Unmanaged                            = "Unmanaged"
    55  	UnmanagedMessageTmpl                 = "No controller is managing this resource. Check if a ConfigConnectorContext exists for resource's namespace, '%v'"
    56  	ControllerFinalizerName              = "cnrm.cloud.google.com/finalizer"
    57  	DeletionDefenderFinalizerName        = "cnrm.cloud.google.com/deletion-defender"
    58  	DependencyNotReady                   = "DependencyNotReady"
    59  	DependencyNotFound                   = "DependencyNotFound"
    60  	DependencyInvalid                    = "DependencyInvalid"
    61  	ManagementConflict                   = "ManagementConflict"
    62  	PreActuationTransformFailed          = "PreActuationTransformFailed"
    63  	PostActuationTransformFailed         = "PostActuationTransformFailed"
    64  	DeletionPolicyDelete                 = "delete"
    65  	DeletionPolicyAbandon                = "abandon"
    66  	AnnotationPrefix                     = CNRMGroup
    67  	NamespaceEnvVar                      = "NAMESPACE"
    68  	ImmediateReconcileRequestsBufferSize = 10000
    69  	MaxNumResourceWatcherRoutines        = 10000
    70  
    71  	ControllerManagedFieldManager = "cnrm-controller-manager"
    72  	UnmanagedDetectorFieldManager = "cnrm-unmanaged-detector"
    73  	SupportsSSAManager            = "supports-ssa"
    74  
    75  	// Management conflict prevention policies
    76  	ManagementConflictPreventionPolicyNone     = "none"
    77  	ManagementConflictPreventionPolicyResource = "resource"
    78  
    79  	// State into spec annotation values
    80  	StateMergeIntoSpec = "merge"
    81  	StateAbsentInSpec  = "absent"
    82  
    83  	// Core kubernetes constants
    84  	LastAppliedConfigurationAnnotation = "kubectl.kubernetes.io/last-applied-configuration"
    85  	ManagedFieldsTypeFieldsV1          = "FieldsV1"
    86  
    87  	ResourceIDFieldName = "resourceID"
    88  	ResourceIDFieldPath = "spec." + ResourceIDFieldName
    89  
    90  	// selfLink may not present in every KRM resource status.
    91  	SelfLinkFieldName = "selfLink"
    92  
    93  	StabilityLevelStable = "stable"
    94  	StabilityLevelAlpha  = "alpha"
    95  
    96  	KCCAPIVersion         = "v1beta1"
    97  	KCCAPIVersionV1Alpha1 = "v1alpha1"
    98  )
    99  
   100  var (
   101  	DeletionPolicyAnnotation             = FormatAnnotation("deletion-policy")
   102  	ReconcileIntervalInSecondsAnnotation = FormatAnnotation("reconcile-interval-in-seconds")
   103  
   104  	// Annotations for Container objects
   105  	ProjectIDAnnotation  = FormatAnnotation("project-id")
   106  	FolderIDAnnotation   = FormatAnnotation("folder-id")
   107  	OrgIDAnnotation      = FormatAnnotation("organization-id")
   108  	ContainerAnnotations = []string{
   109  		ProjectIDAnnotation,
   110  		FolderIDAnnotation,
   111  		OrgIDAnnotation,
   112  	}
   113  
   114  	ManagementConflictPreventionPolicyAnnotation               = "management-conflict-prevention-policy"
   115  	ManagementConflictPreventionPolicyFullyQualifiedAnnotation = FormatAnnotation(ManagementConflictPreventionPolicyAnnotation)
   116  	ManagementConflictPreventionPolicyValues                   = []string{
   117  		ManagementConflictPreventionPolicyNone,
   118  		ManagementConflictPreventionPolicyResource,
   119  	}
   120  
   121  	KCCComponentLabel    = FormatAnnotation("component")
   122  	KCCSystemLabel       = FormatAnnotation("system")
   123  	KCCVersionLabel      = FormatAnnotation("version")
   124  	ScopedNamespaceLabel = FormatAnnotation("scoped-namespace")
   125  	DCL2CRDLabel         = FormatAnnotation("dcl2crd")
   126  	KCCStabilityLabel    = FormatAnnotation("stability-level")
   127  
   128  	MutableButUnreadableFieldsAnnotation = FormatAnnotation("mutable-but-unreadable-fields")
   129  	ObservedSecretVersionsAnnotation     = FormatAnnotation("observed-secret-versions")
   130  
   131  	SupportsSSAAnnotation = FormatAnnotation("supports-ssa")
   132  
   133  	BlueprintAttributionAnnotation = FormatAnnotation("blueprint")
   134  
   135  	StateIntoSpecAnnotation       = FormatAnnotation("state-into-spec")
   136  	StateIntoSpecAnnotationValues = []string{
   137  		StateMergeIntoSpec,
   138  		StateAbsentInSpec,
   139  	}
   140  	// TODO(kcc-eng): Adjust the timeout back down after b/237398742 is fixed.
   141  	WebhookTimeoutSeconds = int32(10)
   142  
   143  	ReservedStatusFieldNamesForFutureUse = []string{"generation"}
   144  
   145  	NamespaceIDConfigMapNN = types.NamespacedName{
   146  		Namespace: SystemNamespace,
   147  		Name:      "namespace-id",
   148  	}
   149  
   150  	// IgnoredKindList contains special or deprecated Kinds that should be
   151  	// ignored by the controllers.
   152  	IgnoredKindList = map[string]bool{
   153  		// ServiceMapping is a special resource type that does not make a call
   154  		// to an underlying GCP API.
   155  		// In addition, KCC no longer supports ServiceMapping CRD as of v1.50.0.
   156  		"ServiceMapping": true,
   157  		// KCC no longer supports GameServicesRealm CRD as of v1.101.0.
   158  		"GameServicesRealm": true,
   159  	}
   160  )
   161  
   162  func FormatAnnotation(annotationName string) string {
   163  	return fmt.Sprintf("%v/%v", AnnotationPrefix, annotationName)
   164  }
   165  

View as plain text