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

     1  /*
     2  Copyright 2020 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 v1alpha4
    18  
    19  import (
    20  	corev1 "k8s.io/api/core/v1"
    21  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    22  
    23  	clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
    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  	Resources []ResourceRef `json:"resources,omitempty"`
    46  
    47  	// Strategy is the strategy to be used during applying resources. Defaults to ApplyOnce. This field is immutable.
    48  	// +kubebuilder:validation:Enum=ApplyOnce
    49  	// +optional
    50  	Strategy string `json:"strategy,omitempty"`
    51  }
    52  
    53  // ANCHOR_END: ClusterResourceSetSpec
    54  
    55  // ClusterResourceSetResourceKind is a string representation of a ClusterResourceSet resource kind.
    56  type ClusterResourceSetResourceKind string
    57  
    58  // Define the ClusterResourceSetResourceKind constants.
    59  const (
    60  	SecretClusterResourceSetResourceKind    ClusterResourceSetResourceKind = "Secret"
    61  	ConfigMapClusterResourceSetResourceKind ClusterResourceSetResourceKind = "ConfigMap"
    62  )
    63  
    64  // ResourceRef specifies a resource.
    65  type ResourceRef struct {
    66  	// Name of the resource that is in the same namespace with ClusterResourceSet object.
    67  	// +kubebuilder:validation:MinLength=1
    68  	Name string `json:"name"`
    69  
    70  	// Kind of the resource. Supported kinds are: Secrets and ConfigMaps.
    71  	// +kubebuilder:validation:Enum=Secret;ConfigMap
    72  	Kind string `json:"kind"`
    73  }
    74  
    75  // ClusterResourceSetStrategy is a string representation of a ClusterResourceSet Strategy.
    76  type ClusterResourceSetStrategy string
    77  
    78  const (
    79  	// ClusterResourceSetStrategyApplyOnce is the default strategy a ClusterResourceSet strategy is assigned by
    80  	// ClusterResourceSet controller after being created if not specified by user.
    81  	ClusterResourceSetStrategyApplyOnce ClusterResourceSetStrategy = "ApplyOnce"
    82  )
    83  
    84  // SetTypedStrategy sets the Strategy field to the string representation of ClusterResourceSetStrategy.
    85  func (c *ClusterResourceSetSpec) SetTypedStrategy(p ClusterResourceSetStrategy) {
    86  	c.Strategy = string(p)
    87  }
    88  
    89  // ANCHOR: ClusterResourceSetStatus
    90  
    91  // ClusterResourceSetStatus defines the observed state of ClusterResourceSet.
    92  type ClusterResourceSetStatus struct {
    93  	// ObservedGeneration reflects the generation of the most recently observed ClusterResourceSet.
    94  	// +optional
    95  	ObservedGeneration int64 `json:"observedGeneration,omitempty"`
    96  
    97  	// Conditions defines current state of the ClusterResourceSet.
    98  	// +optional
    99  	Conditions clusterv1alpha4.Conditions `json:"conditions,omitempty"`
   100  }
   101  
   102  // ANCHOR_END: ClusterResourceSetStatus
   103  
   104  // GetConditions returns the set of conditions for this object.
   105  func (m *ClusterResourceSet) GetConditions() clusterv1alpha4.Conditions {
   106  	return m.Status.Conditions
   107  }
   108  
   109  // SetConditions sets the conditions on this object.
   110  func (m *ClusterResourceSet) SetConditions(conditions clusterv1alpha4.Conditions) {
   111  	m.Status.Conditions = conditions
   112  }
   113  
   114  // +kubebuilder:object:root=true
   115  // +kubebuilder:unservedversion
   116  // +kubebuilder:deprecatedversion
   117  // +kubebuilder:resource:path=clusterresourcesets,scope=Namespaced,categories=cluster-api
   118  // +kubebuilder:subresource:status
   119  // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of ClusterResourceSet"
   120  
   121  // ClusterResourceSet is the Schema for the clusterresourcesets API.
   122  //
   123  // Deprecated: This type will be removed in one of the next releases.
   124  type ClusterResourceSet struct {
   125  	metav1.TypeMeta   `json:",inline"`
   126  	metav1.ObjectMeta `json:"metadata,omitempty"`
   127  
   128  	Spec   ClusterResourceSetSpec   `json:"spec,omitempty"`
   129  	Status ClusterResourceSetStatus `json:"status,omitempty"`
   130  }
   131  
   132  // +kubebuilder:object:root=true
   133  
   134  // ClusterResourceSetList contains a list of ClusterResourceSet.
   135  //
   136  // Deprecated: This type will be removed in one of the next releases.
   137  type ClusterResourceSetList struct {
   138  	metav1.TypeMeta `json:",inline"`
   139  	metav1.ListMeta `json:"metadata,omitempty"`
   140  	Items           []ClusterResourceSet `json:"items"`
   141  }
   142  
   143  func init() {
   144  	objectTypes = append(objectTypes, &ClusterResourceSet{}, &ClusterResourceSetList{})
   145  }