github.com/rancher/types@v0.0.0-20220328215343-4370ff10ecd5/apis/management.cattle.io/v3/cluster_types.go (about) 1 package v3 2 3 import ( 4 "bytes" 5 "encoding/gob" 6 "strings" 7 8 "github.com/rancher/norman/condition" 9 "github.com/rancher/norman/types" 10 "github.com/sirupsen/logrus" 11 v1 "k8s.io/api/core/v1" 12 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 13 "k8s.io/apimachinery/pkg/version" 14 ) 15 16 func init() { 17 gob.Register(map[string]interface{}{}) 18 gob.Register([]interface{}{}) 19 } 20 21 type ClusterConditionType string 22 23 const ( 24 ClusterActionGenerateKubeconfig = "generateKubeconfig" 25 ClusterActionImportYaml = "importYaml" 26 ClusterActionExportYaml = "exportYaml" 27 ClusterActionViewMonitoring = "viewMonitoring" 28 ClusterActionEditMonitoring = "editMonitoring" 29 ClusterActionEnableMonitoring = "enableMonitoring" 30 ClusterActionDisableMonitoring = "disableMonitoring" 31 ClusterActionBackupEtcd = "backupEtcd" 32 ClusterActionRestoreFromEtcdBackup = "restoreFromEtcdBackup" 33 ClusterActionRotateCertificates = "rotateCertificates" 34 ClusterActionRunSecurityScan = "runSecurityScan" 35 ClusterActionSaveAsTemplate = "saveAsTemplate" 36 37 // ClusterConditionReady Cluster ready to serve API (healthy when true, unhealthy when false) 38 ClusterConditionReady condition.Cond = "Ready" 39 ClusterConditionPending condition.Cond = "Pending" 40 ClusterConditionCertsGenerated condition.Cond = "CertsGenerated" 41 ClusterConditionEtcd condition.Cond = "etcd" 42 ClusterConditionProvisioned condition.Cond = "Provisioned" 43 ClusterConditionUpdated condition.Cond = "Updated" 44 ClusterConditionUpgraded condition.Cond = "Upgraded" 45 ClusterConditionWaiting condition.Cond = "Waiting" 46 ClusterConditionRemoved condition.Cond = "Removed" 47 // ClusterConditionNoDiskPressure true when all cluster nodes have sufficient disk 48 ClusterConditionNoDiskPressure condition.Cond = "NoDiskPressure" 49 // ClusterConditionNoMemoryPressure true when all cluster nodes have sufficient memory 50 ClusterConditionNoMemoryPressure condition.Cond = "NoMemoryPressure" 51 // ClusterConditionconditionDefaultProjectCreated true when default project has been created 52 ClusterConditionconditionDefaultProjectCreated condition.Cond = "DefaultProjectCreated" 53 // ClusterConditionconditionSystemProjectCreated true when system project has been created 54 ClusterConditionconditionSystemProjectCreated condition.Cond = "SystemProjectCreated" 55 // ClusterConditionDefaultNamespaceAssigned true when cluster's default namespace has been initially assigned 56 ClusterConditionDefaultNamespaceAssigned condition.Cond = "DefaultNamespaceAssigned" 57 // ClusterConditionSystemNamespacesAssigned true when cluster's system namespaces has been initially assigned to 58 // a system project 59 ClusterConditionSystemNamespacesAssigned condition.Cond = "SystemNamespacesAssigned" 60 ClusterConditionAddonDeploy condition.Cond = "AddonDeploy" 61 ClusterConditionSystemAccountCreated condition.Cond = "SystemAccountCreated" 62 ClusterConditionAgentDeployed condition.Cond = "AgentDeployed" 63 ClusterConditionGlobalAdminsSynced condition.Cond = "GlobalAdminsSynced" 64 ClusterConditionInitialRolesPopulated condition.Cond = "InitialRolesPopulated" 65 ClusterConditionServiceAccountMigrated condition.Cond = "ServiceAccountMigrated" 66 ClusterConditionPrometheusOperatorDeployed condition.Cond = "PrometheusOperatorDeployed" 67 ClusterConditionMonitoringEnabled condition.Cond = "MonitoringEnabled" 68 ClusterConditionAlertingEnabled condition.Cond = "AlertingEnabled" 69 ClusterConditionSecretsMigrated condition.Cond = "SecretsMigrated" 70 71 ClusterDriverImported = "imported" 72 ClusterDriverLocal = "local" 73 ClusterDriverRKE = "rancherKubernetesEngine" 74 ClusterDriverK3s = "k3s" 75 ClusterDriverK3os = "k3os" 76 ) 77 78 // +genclient 79 // +genclient:nonNamespaced 80 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 81 82 type Cluster struct { 83 metav1.TypeMeta `json:",inline"` 84 // Standard object’s metadata. More info: 85 // https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata 86 metav1.ObjectMeta `json:"metadata,omitempty"` 87 // Specification of the desired behavior of the the cluster. More info: 88 // https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status 89 Spec ClusterSpec `json:"spec"` 90 // Most recent observed status of the cluster. More info: 91 // https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status 92 Status ClusterStatus `json:"status"` 93 } 94 95 type ClusterSpecBase struct { 96 DesiredAgentImage string `json:"desiredAgentImage"` 97 DesiredAuthImage string `json:"desiredAuthImage"` 98 AgentImageOverride string `json:"agentImageOverride"` 99 RancherKubernetesEngineConfig *RancherKubernetesEngineConfig `json:"rancherKubernetesEngineConfig,omitempty"` 100 DefaultPodSecurityPolicyTemplateName string `json:"defaultPodSecurityPolicyTemplateName,omitempty" norman:"type=reference[podSecurityPolicyTemplate]"` 101 DefaultClusterRoleForProjectMembers string `json:"defaultClusterRoleForProjectMembers,omitempty" norman:"type=reference[roleTemplate]"` 102 DockerRootDir string `json:"dockerRootDir,omitempty" norman:"default=/var/lib/docker"` 103 EnableNetworkPolicy *bool `json:"enableNetworkPolicy" norman:"default=false"` 104 EnableClusterAlerting bool `json:"enableClusterAlerting" norman:"default=false"` 105 EnableClusterMonitoring bool `json:"enableClusterMonitoring" norman:"default=false"` 106 WindowsPreferedCluster bool `json:"windowsPreferedCluster" norman:"noupdate"` 107 LocalClusterAuthEndpoint LocalClusterAuthEndpoint `json:"localClusterAuthEndpoint,omitempty"` 108 ScheduledClusterScan *ScheduledClusterScan `json:"scheduledClusterScan,omitempty"` 109 } 110 111 type ClusterSpec struct { 112 ClusterSpecBase 113 DisplayName string `json:"displayName" norman:"required"` 114 Description string `json:"description"` 115 Internal bool `json:"internal" norman:"nocreate,noupdate"` 116 K3sConfig *K3sConfig `json:"k3sConfig,omitempty"` 117 ImportedConfig *ImportedConfig `json:"importedConfig,omitempty" norman:"nocreate,noupdate"` 118 GoogleKubernetesEngineConfig *MapStringInterface `json:"googleKubernetesEngineConfig,omitempty"` 119 AzureKubernetesServiceConfig *MapStringInterface `json:"azureKubernetesServiceConfig,omitempty"` 120 AmazonElasticContainerServiceConfig *MapStringInterface `json:"amazonElasticContainerServiceConfig,omitempty"` 121 GenericEngineConfig *MapStringInterface `json:"genericEngineConfig,omitempty"` 122 ClusterTemplateName string `json:"clusterTemplateName,omitempty" norman:"type=reference[clusterTemplate],nocreate,noupdate"` 123 ClusterTemplateRevisionName string `json:"clusterTemplateRevisionName,omitempty" norman:"type=reference[clusterTemplateRevision]"` 124 ClusterTemplateAnswers Answer `json:"answers,omitempty"` 125 ClusterTemplateQuestions []Question `json:"questions,omitempty" norman:"nocreate,noupdate"` 126 } 127 128 type ImportedConfig struct { 129 KubeConfig string `json:"kubeConfig" norman:"type=password"` 130 } 131 132 type ClusterStatus struct { 133 // Conditions represent the latest available observations of an object's current state: 134 // More info: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#typical-status-properties 135 Conditions []ClusterCondition `json:"conditions,omitempty"` 136 // Component statuses will represent cluster's components (etcd/controller/scheduler) health 137 // https://kubernetes.io/docs/api-reference/v1.8/#componentstatus-v1-core 138 Driver string `json:"driver"` 139 AgentImage string `json:"agentImage"` 140 AgentFeatures map[string]bool `json:"agentFeatures,omitempty"` 141 AuthImage string `json:"authImage"` 142 ComponentStatuses []ClusterComponentStatus `json:"componentStatuses,omitempty"` 143 APIEndpoint string `json:"apiEndpoint,omitempty"` 144 ServiceAccountToken string `json:"serviceAccountToken,omitempty"` 145 CACert string `json:"caCert,omitempty"` 146 Capacity v1.ResourceList `json:"capacity,omitempty"` 147 Allocatable v1.ResourceList `json:"allocatable,omitempty"` 148 AppliedSpec ClusterSpec `json:"appliedSpec,omitempty"` 149 FailedSpec *ClusterSpec `json:"failedSpec,omitempty"` 150 Requested v1.ResourceList `json:"requested,omitempty"` 151 Limits v1.ResourceList `json:"limits,omitempty"` 152 Version *version.Info `json:"version,omitempty"` 153 AppliedPodSecurityPolicyTemplateName string `json:"appliedPodSecurityPolicyTemplateId"` 154 AppliedEnableNetworkPolicy bool `json:"appliedEnableNetworkPolicy" norman:"nocreate,noupdate,default=false"` 155 Capabilities Capabilities `json:"capabilities,omitempty"` 156 MonitoringStatus *MonitoringStatus `json:"monitoringStatus,omitempty" norman:"nocreate,noupdate"` 157 NodeVersion int `json:"nodeVersion,omitempty"` 158 NodeCount int `json:"nodeCount,omitempty" norman:"nocreate,noupdate"` 159 IstioEnabled bool `json:"istioEnabled,omitempty" norman:"nocreate,noupdate,default=false"` 160 CertificatesExpiration map[string]CertExpiration `json:"certificatesExpiration,omitempty"` 161 ScheduledClusterScanStatus *ScheduledClusterScanStatus `json:"scheduledClusterScanStatus,omitempty"` 162 CurrentCisRunName string `json:"currentCisRunName,omitempty"` 163 PrivateRegistrySecret string `json:"privateRegistrySecret,omitempty" norman:"nocreate,noupdate"` 164 S3CredentialSecret string `json:"s3CredentialSecret,omitempty" norman:"nocreate,noupdate"` 165 WeavePasswordSecret string `json:"weavePasswordSecret,omitempty" norman:"nocreate,noupdate"` 166 VsphereSecret string `json:"vsphereSecret,omitempty" norman:"nocreate,noupdate"` 167 VirtualCenterSecret string `json:"virtualCenterSecret,omitempty" norman:"nocreate,noupdate"` 168 OpenStackSecret string `json:"openStackSecret,omitempty" norman:"nocreate,noupdate"` 169 AADClientSecret string `json:"aadClientSecret,omitempty" norman:"nocreate,noupdate"` 170 AADClientCertSecret string `json:"aadClientCertSecret,omitempty" norman:"nocreate,noupdate"` 171 } 172 173 type ClusterComponentStatus struct { 174 Name string `json:"name"` 175 Conditions []v1.ComponentCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,2,rep,name=conditions"` 176 } 177 178 type ClusterCondition struct { 179 // Type of cluster condition. 180 Type ClusterConditionType `json:"type"` 181 // Status of the condition, one of True, False, Unknown. 182 Status v1.ConditionStatus `json:"status"` 183 // The last time this condition was updated. 184 LastUpdateTime string `json:"lastUpdateTime,omitempty"` 185 // Last time the condition transitioned from one status to another. 186 LastTransitionTime string `json:"lastTransitionTime,omitempty"` 187 // The reason for the condition's last transition. 188 Reason string `json:"reason,omitempty"` 189 // Human-readable message indicating details about last transition 190 Message string `json:"message,omitempty"` 191 } 192 193 type MapStringInterface map[string]interface{} 194 195 func (m *MapStringInterface) DeepCopy() *MapStringInterface { 196 var buf bytes.Buffer 197 enc := gob.NewEncoder(&buf) 198 dec := gob.NewDecoder(&buf) 199 err := enc.Encode(m) 200 if err != nil { 201 logrus.Errorf("error while deep copying MapStringInterface %v", err) 202 return nil 203 } 204 205 var copy MapStringInterface 206 err = dec.Decode(©) 207 if err != nil { 208 logrus.Errorf("error while deep copying MapStringInterface %v", err) 209 return nil 210 } 211 212 return © 213 } 214 215 type ClusterRegistrationToken struct { 216 types.Namespaced 217 218 metav1.TypeMeta `json:",inline"` 219 // Standard object’s metadata. More info: 220 // https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata 221 metav1.ObjectMeta `json:"metadata,omitempty"` 222 // Specification of the desired behavior of the the cluster. More info: 223 // https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status 224 Spec ClusterRegistrationTokenSpec `json:"spec"` 225 // Most recent observed status of the cluster. More info: 226 // https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status 227 Status ClusterRegistrationTokenStatus `json:"status"` 228 } 229 230 func (c *ClusterRegistrationToken) ObjClusterName() string { 231 return c.Spec.ObjClusterName() 232 } 233 234 type ClusterRegistrationTokenSpec struct { 235 ClusterName string `json:"clusterName" norman:"required,type=reference[cluster]"` 236 } 237 238 func (c *ClusterRegistrationTokenSpec) ObjClusterName() string { 239 return c.ClusterName 240 } 241 242 type ClusterRegistrationTokenStatus struct { 243 InsecureCommand string `json:"insecureCommand"` 244 Command string `json:"command"` 245 WindowsNodeCommand string `json:"windowsNodeCommand"` 246 NodeCommand string `json:"nodeCommand"` 247 ManifestURL string `json:"manifestUrl"` 248 Token string `json:"token"` 249 } 250 251 type GenerateKubeConfigOutput struct { 252 Config string `json:"config"` 253 } 254 255 type ExportOutput struct { 256 YAMLOutput string `json:"yamlOutput"` 257 } 258 259 type ImportClusterYamlInput struct { 260 YAML string `json:"yaml,omitempty"` 261 DefaultNamespace string `json:"defaultNamespace,omitempty"` 262 Namespace string `json:"namespace,omitempty"` 263 ProjectName string `json:"projectName,omitempty" norman:"type=reference[project]"` 264 } 265 266 func (i *ImportClusterYamlInput) ObjClusterName() string { 267 if parts := strings.SplitN(i.ProjectName, ":", 2); len(parts) == 2 { 268 return parts[0] 269 } 270 return "" 271 } 272 273 type ImportYamlOutput struct { 274 Message string `json:"message,omitempty"` 275 } 276 277 type Capabilities struct { 278 LoadBalancerCapabilities LoadBalancerCapabilities `json:"loadBalancerCapabilities,omitempty"` 279 IngressCapabilities []IngressCapabilities `json:"ingressCapabilities,omitempty"` 280 NodePoolScalingSupported bool `json:"nodePoolScalingSupported,omitempty"` 281 NodePortRange string `json:"nodePortRange,omitempty"` 282 TaintSupport *bool `json:"taintSupport,omitempty"` 283 PspEnabled bool `json:"pspEnabled,omitempty"` 284 } 285 286 type LoadBalancerCapabilities struct { 287 Enabled *bool `json:"enabled,omitempty"` 288 Provider string `json:"provider,omitempty"` 289 ProtocolsSupported []string `json:"protocolsSupported,omitempty"` 290 HealthCheckSupported bool `json:"healthCheckSupported,omitempty"` 291 } 292 293 type IngressCapabilities struct { 294 IngressProvider string `json:"ingressProvider,omitempty"` 295 CustomDefaultBackend *bool `json:"customDefaultBackend,omitempty"` 296 } 297 298 type MonitoringInput struct { 299 Version string `json:"version,omitempty"` 300 Answers map[string]string `json:"answers,omitempty"` 301 } 302 303 type MonitoringOutput struct { 304 Version string `json:"version,omitempty"` 305 Answers map[string]string `json:"answers,omitempty"` 306 } 307 308 type RestoreFromEtcdBackupInput struct { 309 EtcdBackupName string `json:"etcdBackupName,omitempty" norman:"type=reference[etcdBackup]"` 310 RestoreRkeConfig string `json:"restoreRkeConfig,omitempty"` 311 } 312 313 type RotateCertificateInput struct { 314 CACertificates bool `json:"caCertificates,omitempty"` 315 Services []string `json:"services,omitempty" norman:"type=enum,options=etcd|kubelet|kube-apiserver|kube-proxy|kube-scheduler|kube-controller-manager"` 316 } 317 318 type RotateCertificateOutput struct { 319 Message string `json:"message,omitempty"` 320 } 321 322 type LocalClusterAuthEndpoint struct { 323 Enabled bool `json:"enabled"` 324 FQDN string `json:"fqdn,omitempty"` 325 CACerts string `json:"caCerts,omitempty"` 326 } 327 328 type CertExpiration struct { 329 ExpirationDate string `json:"expirationDate,omitempty"` 330 } 331 332 type SaveAsTemplateInput struct { 333 ClusterTemplateName string `json:"clusterTemplateName,omitempty"` 334 ClusterTemplateRevisionName string `json:"clusterTemplateRevisionName,omitempty"` 335 } 336 337 type SaveAsTemplateOutput struct { 338 ClusterTemplateName string `json:"clusterTemplateName,omitempty"` 339 ClusterTemplateRevisionName string `json:"clusterTemplateRevisionName,omitempty"` 340 }