...

Source file src/edge-infra.dev/pkg/k8s/konfigkonnector/apis/meta/conditions.go

Documentation: edge-infra.dev/pkg/k8s/konfigkonnector/apis/meta

     1  package meta
     2  
     3  import (
     4  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/k8s/v1alpha1"
     5  	v1 "k8s.io/api/core/v1"
     6  )
     7  
     8  // These constants define Condition reasons for K8s Config Connector resources
     9  // https://cloud.google.com/config-connector/docs/how-to/monitoring-your-resources
    10  const (
    11  	// Occurs when a resource's underlying resource is being updated.
    12  	UpdatingReason string = "Updating"
    13  
    14  	// Occurs when a resource's reconciliation has succeeded.
    15  	UpToDateReason string = "UpToDate"
    16  
    17  	// Occurs when a resource's reconciliation has failed.
    18  	UpdateFailedReason string = "UpdateFailed"
    19  
    20  	// Occurs when a referenced resource is not ready.
    21  	DependencyNotReadyReason string = "DependencyNotReady"
    22  
    23  	// Occurs when a referenced resource or Kubernetes Secret is not found.
    24  	DependencyNotFoundReason string = "DependencyNotFound"
    25  
    26  	// Occurs when a reference is invalid.
    27  	// For example, suppose a resource that references a Kubernetes Secret. If the Secret exists, but if it does not contain the key that is being referenced, then the reference is said to be invalid.
    28  	DependencyInvalidReason string = "DependencyInvalid"
    29  
    30  	// Occurs when a resource is being deleted from the Kubernetes API Server.
    31  	DeletingReason string = "Deleting"
    32  
    33  	// Occurs when a resource has successfully been deleted from the Kubernetes API Server.
    34  	DeletedReason string = "Deleted"
    35  
    36  	// Occurs when a resource has failed to be deleted from the Kubernetes API Server.
    37  	DeleteFailedReason string = "DeleteFailed"
    38  
    39  	// Occurs when a resource fails to take ownership of the underlying resource.
    40  	ManagementConflictReason string = "ManagementConflict"
    41  
    42  	// Occurs when a resource fails to perform pre-actuation transformations. This event type likely means that the resource configuration is invalid.
    43  	PreActuationTransformFailedReason string = "PreActuationTransformFailed"
    44  
    45  	// Occurs when a resource fails to perform post-actuation transformations.
    46  	PostActuationTransformFailedReason string = "PostActuationTransformFailed"
    47  )
    48  
    49  // IsReady determines if a GCP resource is Ready.
    50  func IsReady(conditions []v1alpha1.Condition) (bool, string) {
    51  	return IsCondition(conditions, "Ready", v1.ConditionTrue)
    52  }
    53  
    54  // IsCondition generically determines if the provided conditions contains
    55  // a condition of the provided type with the provided status
    56  func IsCondition(conditions []v1alpha1.Condition, conditionType string, conditionStatus v1.ConditionStatus) (bool, string) {
    57  	reason := ""
    58  	for _, condition := range conditions {
    59  		if condition.Type == conditionType {
    60  			return condition.Status == conditionStatus, condition.Reason
    61  		}
    62  	}
    63  	return false, reason
    64  }
    65  

View as plain text