k8c.io/api/v3@v3.0.0-20230904060738-b0a93889c0b6/pkg/apis/ee.kubermatic/v1/seed.go (about)

     1  /*
     2  Copyright 2023 The Kubermatic Kubernetes Platform contributors.
     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 v1
    18  
    19  import (
    20  	kubermaticv1 "k8c.io/api/v3/pkg/apis/kubermatic/v1"
    21  
    22  	corev1 "k8s.io/api/core/v1"
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  )
    25  
    26  // +kubebuilder:validation:Enum=Healthy;Unhealthy;Invalid;Terminating;Paused
    27  
    28  type SeedPhase string
    29  
    30  // These are the valid phases of a seed.
    31  const (
    32  	// SeedPhaseHealthy means the seed is reachable and was successfully reconciled.
    33  	SeedPhaseHealthy SeedPhase = "Healthy"
    34  
    35  	// SeedPhaseUnhealthy means the KKP resources on the seed cluster could not be
    36  	// successfully reconciled.
    37  	SeedPhaseUnhealthy SeedPhase = "Unhealthy"
    38  
    39  	// SeedPhaseInvalid means the seed kubeconfig is defunct.
    40  	SeedPhaseInvalid SeedPhase = "Invalid"
    41  
    42  	// SeedPhaseTerminating means the seed is currently being deleted.
    43  	SeedPhaseTerminating SeedPhase = "Terminating"
    44  
    45  	// SeedPhasePaused means the seed is not being reconciled because the SkipReconciling
    46  	// annotation is set.
    47  	SeedPhasePaused SeedPhase = "Paused"
    48  )
    49  
    50  // +genclient
    51  // +kubebuilder:object:generate=true
    52  // +kubebuilder:object:root=true
    53  // +kubebuilder:subresource:status
    54  // +kubebuilder:printcolumn:JSONPath=".status.clusters",name="Clusters",type="integer"
    55  // +kubebuilder:printcolumn:JSONPath=".spec.location",name="Location",type="string"
    56  // +kubebuilder:printcolumn:JSONPath=".status.versions.kubermatic",name="KKP Version",type="string"
    57  // +kubebuilder:printcolumn:JSONPath=".status.versions.cluster",name="Cluster Version",type="string"
    58  // +kubebuilder:printcolumn:JSONPath=".status.phase",name="Phase",type="string"
    59  // +kubebuilder:printcolumn:JSONPath=".metadata.creationTimestamp",name="Age",type="date"
    60  
    61  // Seed is the type representing a Seed cluster. Seed clusters host the the control planes
    62  // for KKP user clusters. Seedlets are responsible for registering a seed cluster in the
    63  // KKP management system, similar to how a kubelet registers a node.
    64  type Seed struct {
    65  	metav1.TypeMeta   `json:",inline"`
    66  	metav1.ObjectMeta `json:"metadata,omitempty"`
    67  
    68  	Spec SeedSpec `json:"spec"`
    69  
    70  	//nolint:staticcheck
    71  	//lint:ignore SA5008 omitgenyaml is used by the example-yaml-generator
    72  	Status SeedStatus `json:"status,omitempty,omitgenyaml"`
    73  }
    74  
    75  // The spec for a seed cluster.
    76  type SeedSpec struct {
    77  	// Optional: Country of the seed as ISO-3166 two-letter code, e.g. DE or UK.
    78  	// For informational purposes in the Kubermatic dashboard only.
    79  	Country string `json:"country,omitempty"`
    80  	// Optional: Detailed location of the cluster, like "Hamburg" or "Datacenter 7".
    81  	// For informational purposes in the Kubermatic dashboard only.
    82  	Location string `json:"location,omitempty"`
    83  	// Datacenters contains a map of all datacenters (DCs) on this seed. The datacenter
    84  	// names are not globally unique, i.e. two seeds can both have a "test" datacenter.
    85  	Datacenters map[string]kubermaticv1.DatacenterSpec `json:"datacenters,omitempty"`
    86  }
    87  
    88  // SeedStatus contains runtime information regarding the seed.
    89  type SeedStatus struct {
    90  	// Phase contains a human readable text to indicate the seed cluster status. No logic should be tied
    91  	// to this field, as its content can change in between KKP releases.
    92  	Phase SeedPhase `json:"phase,omitempty"`
    93  
    94  	// +kubebuilder:default=0
    95  	// +kubebuilder:validation:Minimum:=0
    96  
    97  	// Clusters is the total number of user clusters that exist on this seed, the sum across all its
    98  	// datacenters.
    99  	Clusters int `json:"clusters"`
   100  
   101  	// Versions contains information regarding versions of components in the cluster and the cluster
   102  	// itself.
   103  	// +optional
   104  	Versions SeedVersionsStatus `json:"versions,omitempty"`
   105  
   106  	// Datacenters contains a map of all datacenter statuses on this seed.
   107  	Datacenters map[string]kubermaticv1.DatacenterStatus `json:"datacenters,omitempty"`
   108  
   109  	// Conditions contains conditions the seed is in, its primary use case is status signaling
   110  	// between controllers or between controllers and the API.
   111  	// +optional
   112  	Conditions map[SeedConditionType]SeedCondition `json:"conditions,omitempty"`
   113  }
   114  
   115  // +kubebuilder:validation:Enum=KubeconfigValid;ResourcesReconciled;ClusterInitialized
   116  
   117  // SeedConditionType is used to indicate the type of a seed condition. For all condition
   118  // types, the `true` value must indicate success.
   119  type SeedConditionType string
   120  
   121  const (
   122  	// SeedConditionKubeconfigValid indicates that the configured kubeconfig for the seed is valid.
   123  	// The seed-sync controller manages this condition.
   124  	SeedConditionKubeconfigValid SeedConditionType = "KubeconfigValid"
   125  	// SeedConditionResourcesReconciled indicates that the KKP operator has finished setting up the
   126  	// resources inside the seed cluster.
   127  	SeedConditionResourcesReconciled SeedConditionType = "ResourcesReconciled"
   128  	// SeedConditionClusterInitialized indicates that the KKP operator has finished setting up the
   129  	// CRDs and other prerequisites on the Seed cluster. After this condition is true, other
   130  	// controllers can begin to create watches and reconcile resources (i.e. this condition is
   131  	// a precondition to ResourcesReconciled). Once this condition is true, it is never set to false
   132  	// again.
   133  	SeedConditionClusterInitialized SeedConditionType = "ClusterInitialized"
   134  )
   135  
   136  type SeedCondition struct {
   137  	// Status of the condition, one of True, False, Unknown.
   138  	Status corev1.ConditionStatus `json:"status"`
   139  	// Last time we got an update on a given condition.
   140  	LastHeartbeatTime metav1.Time `json:"lastHeartbeatTime"`
   141  	// Last time the condition transit from one status to another.
   142  	// +optional
   143  	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
   144  	// (brief) reason for the condition's last transition.
   145  	// +optional
   146  	Reason string `json:"reason,omitempty"`
   147  	// Human readable message indicating details about last transition.
   148  	// +optional
   149  	Message string `json:"message,omitempty"`
   150  }
   151  
   152  // SeedVersionsStatus contains information regarding versions of components in the cluster
   153  // and the cluster itself.
   154  type SeedVersionsStatus struct {
   155  	// Kubermatic is the version of the currently deployed KKP components. Note that a permanent
   156  	// version skew between master and seed is not supported and KKP setups should never run for
   157  	// longer times with a skew between the clusters.
   158  	Kubermatic string `json:"kubermatic,omitempty"`
   159  	// Cluster is the Kubernetes version of the cluster's control plane.
   160  	Cluster string `json:"cluster,omitempty"`
   161  }
   162  
   163  // +kubebuilder:object:generate=true
   164  // +kubebuilder:object:root=true
   165  
   166  // SeedList is the type representing a SeedList.
   167  type SeedList struct {
   168  	metav1.TypeMeta `json:",inline"`
   169  	metav1.ListMeta `json:"metadata,omitempty"`
   170  
   171  	// List of seeds
   172  	Items []Seed `json:"items"`
   173  }