sigs.k8s.io/cluster-api@v1.7.1/exp/addons/api/v1beta1/clusterresourceset_types.go (about)

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1beta1
    18  
    19  import (
    20  	corev1 "k8s.io/api/core/v1"
    21  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    22  
    23  	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
    24  )
    25  
    26  const (
    27  	// ClusterResourceSetSecretType is the only accepted type of secret in resources.
    28  	ClusterResourceSetSecretType corev1.SecretType = "addons.cluster.x-k8s.io/resource-set" //nolint:gosec
    29  
    30  	// ClusterResourceSetFinalizer is added to the ClusterResourceSet object for additional cleanup logic on deletion.
    31  	ClusterResourceSetFinalizer = "addons.cluster.x-k8s.io"
    32  )
    33  
    34  // ANCHOR: ClusterResourceSetSpec
    35  
    36  // ClusterResourceSetSpec defines the desired state of ClusterResourceSet.
    37  type ClusterResourceSetSpec struct {
    38  	// Label selector for Clusters. The Clusters that are
    39  	// selected by this will be the ones affected by this ClusterResourceSet.
    40  	// It must match the Cluster labels. This field is immutable.
    41  	// Label selector cannot be empty.
    42  	ClusterSelector metav1.LabelSelector `json:"clusterSelector"`
    43  
    44  	// Resources is a list of Secrets/ConfigMaps where each contains 1 or more resources to be applied to remote clusters.
    45  	// +optional
    46  	Resources []ResourceRef `json:"resources,omitempty"`
    47  
    48  	// Strategy is the strategy to be used during applying resources. Defaults to ApplyOnce. This field is immutable.
    49  	// +kubebuilder:validation:Enum=ApplyOnce;Reconcile
    50  	// +optional
    51  	Strategy string `json:"strategy,omitempty"`
    52  }
    53  
    54  // ANCHOR_END: ClusterResourceSetSpec
    55  
    56  // ClusterResourceSetResourceKind is a string representation of a ClusterResourceSet resource kind.
    57  type ClusterResourceSetResourceKind string
    58  
    59  // Define the ClusterResourceSetResourceKind constants.
    60  const (
    61  	SecretClusterResourceSetResourceKind    ClusterResourceSetResourceKind = "Secret"
    62  	ConfigMapClusterResourceSetResourceKind ClusterResourceSetResourceKind = "ConfigMap"
    63  )
    64  
    65  // ResourceRef specifies a resource.
    66  type ResourceRef struct {
    67  	// Name of the resource that is in the same namespace with ClusterResourceSet object.
    68  	// +kubebuilder:validation:MinLength=1
    69  	Name string `json:"name"`
    70  
    71  	// Kind of the resource. Supported kinds are: Secrets and ConfigMaps.
    72  	// +kubebuilder:validation:Enum=Secret;ConfigMap
    73  	Kind string `json:"kind"`
    74  }
    75  
    76  // ClusterResourceSetStrategy is a string representation of a ClusterResourceSet Strategy.
    77  type ClusterResourceSetStrategy string
    78  
    79  const (
    80  	// ClusterResourceSetStrategyApplyOnce is the default strategy a ClusterResourceSet strategy is assigned by
    81  	// ClusterResourceSet controller after being created if not specified by user.
    82  	ClusterResourceSetStrategyApplyOnce ClusterResourceSetStrategy = "ApplyOnce"
    83  	// ClusterResourceSetStrategyReconcile reapplies the resources managed by a ClusterResourceSet
    84  	// if their normalized hash changes.
    85  	ClusterResourceSetStrategyReconcile ClusterResourceSetStrategy = "Reconcile"
    86  )
    87  
    88  // SetTypedStrategy sets the Strategy field to the string representation of ClusterResourceSetStrategy.
    89  func (c *ClusterResourceSetSpec) SetTypedStrategy(p ClusterResourceSetStrategy) {
    90  	c.Strategy = string(p)
    91  }
    92  
    93  // ANCHOR: ClusterResourceSetStatus
    94  
    95  // ClusterResourceSetStatus defines the observed state of ClusterResourceSet.
    96  type ClusterResourceSetStatus struct {
    97  	// ObservedGeneration reflects the generation of the most recently observed ClusterResourceSet.
    98  	// +optional
    99  	ObservedGeneration int64 `json:"observedGeneration,omitempty"`
   100  
   101  	// Conditions defines current state of the ClusterResourceSet.
   102  	// +optional
   103  	Conditions clusterv1.Conditions `json:"conditions,omitempty"`
   104  }
   105  
   106  // ANCHOR_END: ClusterResourceSetStatus
   107  
   108  // GetConditions returns the set of conditions for this object.
   109  func (m *ClusterResourceSet) GetConditions() clusterv1.Conditions {
   110  	return m.Status.Conditions
   111  }
   112  
   113  // SetConditions sets the conditions on this object.
   114  func (m *ClusterResourceSet) SetConditions(conditions clusterv1.Conditions) {
   115  	m.Status.Conditions = conditions
   116  }
   117  
   118  // +kubebuilder:object:root=true
   119  // +kubebuilder:resource:path=clusterresourcesets,scope=Namespaced,categories=cluster-api
   120  // +kubebuilder:subresource:status
   121  // +kubebuilder:storageversion
   122  // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of ClusterResourceSet"
   123  
   124  // ClusterResourceSet is the Schema for the clusterresourcesets API.
   125  type ClusterResourceSet struct {
   126  	metav1.TypeMeta   `json:",inline"`
   127  	metav1.ObjectMeta `json:"metadata,omitempty"`
   128  
   129  	Spec   ClusterResourceSetSpec   `json:"spec,omitempty"`
   130  	Status ClusterResourceSetStatus `json:"status,omitempty"`
   131  }
   132  
   133  // +kubebuilder:object:root=true
   134  
   135  // ClusterResourceSetList contains a list of ClusterResourceSet.
   136  type ClusterResourceSetList struct {
   137  	metav1.TypeMeta `json:",inline"`
   138  	metav1.ListMeta `json:"metadata,omitempty"`
   139  	Items           []ClusterResourceSet `json:"items"`
   140  }
   141  
   142  func init() {
   143  	objectTypes = append(objectTypes, &ClusterResourceSet{}, &ClusterResourceSetList{})
   144  }