From 6256e1351ffd18d2c2cb2fce5423a71aa9c35d31 Mon Sep 17 00:00:00 2001 From: DingYongliang <1521323439@qq.com> Date: Wed, 18 Sep 2024 17:57:05 +0800 Subject: [PATCH 1/2] feat: add capkk CRDs --- ...structure.cluster.x-k8s.io_kkclusters.yaml | 343 +++++++++++++++ ...structure.cluster.x-k8s.io_kkmachines.yaml | 174 ++++++++ ...e.cluster.x-k8s.io_kkmachinetemplates.yaml | 121 ++++++ pkg/apis/capkk/v1beta1/kkcluster_types.go | 254 +++++++++++ pkg/apis/capkk/v1beta1/kkmachine_types.go | 135 ++++++ .../capkk/v1beta1/kkmachinetemplate_types.go | 77 ++++ pkg/apis/capkk/v1beta1/register.go | 36 ++ .../capkk/v1beta1/zz_generated.deepcopy.go | 400 ++++++++++++++++++ 8 files changed, 1540 insertions(+) create mode 100644 config/capkk/crds/infrastructure.cluster.x-k8s.io_kkclusters.yaml create mode 100644 config/capkk/crds/infrastructure.cluster.x-k8s.io_kkmachines.yaml create mode 100644 config/capkk/crds/infrastructure.cluster.x-k8s.io_kkmachinetemplates.yaml create mode 100644 pkg/apis/capkk/v1beta1/kkcluster_types.go create mode 100644 pkg/apis/capkk/v1beta1/kkmachine_types.go create mode 100644 pkg/apis/capkk/v1beta1/kkmachinetemplate_types.go create mode 100644 pkg/apis/capkk/v1beta1/register.go create mode 100644 pkg/apis/capkk/v1beta1/zz_generated.deepcopy.go diff --git a/config/capkk/crds/infrastructure.cluster.x-k8s.io_kkclusters.yaml b/config/capkk/crds/infrastructure.cluster.x-k8s.io_kkclusters.yaml new file mode 100644 index 000000000..53641f20f --- /dev/null +++ b/config/capkk/crds/infrastructure.cluster.x-k8s.io_kkclusters.yaml @@ -0,0 +1,343 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.15.0 + labels: + cluster.x-k8s.io/v1beta1: v1beta1 + name: kkclusters.infrastructure.cluster.x-k8s.io +spec: + group: infrastructure.cluster.x-k8s.io + names: + categories: + - cluster-api + kind: KKCluster + listKind: KKClusterList + plural: kkclusters + shortNames: + - kkc + singular: kkcluster + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Cluster to which this KKClusters belongs + jsonPath: .metadata.labels.cluster\.x-k8s\.io/cluster-name + name: Cluster + type: string + - description: Cluster infrastructure is ready for SSH instances + jsonPath: .status.ready + name: Ready + type: string + - description: API Endpoint + jsonPath: .spec.controlPlaneEndpoint + name: Endpoint + priority: 1 + type: string + name: v1beta1 + schema: + openAPIV3Schema: + description: KKCluster resource maps a kubernetes cluster, manage and reconcile + cluster status. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: KKClusterSpec defines the desired state of KKCluster. + properties: + clusterGroupName: + description: ClusterGroupName is the group name of kubernetes cluster, + which contains control plane group and worker group. + type: string + configRef: + description: ConfigRef is the reference of Config. + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + controlPlaneEndpoint: + description: ControlPlaneEndpoint represents the endpoint used to + communicate with the control plane. + properties: + host: + description: The hostname on which the API server is serving. + type: string + port: + description: The port on which the API server is serving. + format: int32 + type: integer + required: + - host + - port + type: object + controlPlaneGroupName: + description: ControlPlaneGroupName is the group name of kubernetes + control plane nodes. + type: string + controlPlaneLoadBalancer: + description: ControlPlaneLoadBalancer is optional configuration for + customizing control plane behavior. + properties: + host: + description: The hostname on which the API server is serving. + type: string + type: object + distribution: + description: Distribution represents the Kubernetes distribution type + of the cluster. + type: string + inventoryRef: + description: InventoryRef is the reference of Inventory. + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + nodeSelectorMode: + description: NodeSelectorMode is the select mode of the node selector. + type: string + pipelineRef: + description: ConfigRef is the reference of Pipeline. + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + workerGroupName: + description: WorkerGroupName is the group name of kubernetes worker + nodes. + type: string + required: + - controlPlaneEndpoint + type: object + status: + description: KKClusterStatus defines the observed state of KKCluster. + properties: + conditions: + description: Conditions defines current service state of the KKCluster. + items: + description: Condition defines an observation of a Cluster API resource + operational state. + properties: + lastTransitionTime: + description: |- + Last time the condition transitioned from one status to another. + This should be when the underlying condition changed. If that is not known, then using the time when + the API field changed is acceptable. + format: date-time + type: string + message: + description: |- + A human readable message indicating details about the transition. + This field may be empty. + type: string + reason: + description: |- + The reason for the condition's last transition in CamelCase. + The specific API may choose whether or not this field is considered a guaranteed API. + This field may not be empty. + type: string + severity: + description: |- + Severity provides an explicit classification of Reason code, so the users or machines can immediately + understand the current situation and act accordingly. + The Severity field MUST be set only when Status=False. + type: string + status: + description: Status of the condition, one of True, False, Unknown. + type: string + type: + description: |- + Type of condition in CamelCase or in foo.example.com/CamelCase. + Many .condition.type values are consistent across resources like Available, but because arbitrary conditions + can be useful (see .node.status.conditions), the ability to deconflict is important. + type: string + required: + - lastTransitionTime + - status + - type + type: object + type: array + failureMessage: + description: |- + FailureMessage will be set in the event that there is a terminal problem + reconciling the Machine and will contain a more verbose string suitable + for logging and human consumption. + + + This field should not be set for transitive errors that a controller + faces that are expected to be fixed automatically over + time (like service outages), but instead indicate that something is + fundamentally wrong with the Machine's spec or the configuration of + the controller, and that manual intervention is required. Examples + of terminal errors would be invalid combinations of settings in the + spec, values that are unsupported by the controller, or the + responsible controller itself being critically misconfigured. + + + Any transient errors that occur during the reconciliation of Machines + can be added as events to the Machine object and/or logged in the + controller's output. + type: string + failureReason: + description: |- + FailureReason will be set in the event that there is a terminal problem + reconciling the Machine and will contain a succinct value suitable + for machine interpretation. + + + This field should not be set for transitive errors that a controller + faces that are expected to be fixed automatically over + time (like service outages), but instead indicate that something is + fundamentally wrong with the Machine's spec or the configuration of + the controller, and that manual intervention is required. Examples + of terminal errors would be invalid combinations of settings in the + spec, values that are unsupported by the controller, or the + responsible controller itself being critically misconfigured. + + + Any transient errors that occur during the reconciliation of Machines + can be added as events to the Machine object and/or logged in the + controller's output. + type: string + phase: + description: Phase of KKCluster. + type: string + ready: + default: false + type: boolean + required: + - ready + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/config/capkk/crds/infrastructure.cluster.x-k8s.io_kkmachines.yaml b/config/capkk/crds/infrastructure.cluster.x-k8s.io_kkmachines.yaml new file mode 100644 index 000000000..335a94022 --- /dev/null +++ b/config/capkk/crds/infrastructure.cluster.x-k8s.io_kkmachines.yaml @@ -0,0 +1,174 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.15.0 + labels: + cluster.x-k8s.io/v1beta1: v1beta1 + name: kkmachines.infrastructure.cluster.x-k8s.io +spec: + group: infrastructure.cluster.x-k8s.io + names: + categories: + - cluster-api + kind: KKMachine + listKind: KKMachineList + plural: kkmachines + shortNames: + - kkm + singular: kkmachine + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Cluster to which this KKMachine belongs + jsonPath: .metadata.labels.cluster\.x-k8s\.io/cluster-name + name: Cluster + type: string + - description: Machine ready status + jsonPath: .status.ready + name: Ready + type: string + - description: Machine object which owns with this KKMachine + jsonPath: .metadata.ownerReferences[?(@.kind=="Machine")].name + name: Machine + type: string + name: v1beta1 + schema: + openAPIV3Schema: + description: KKMachine resource maps a machine instance, manage and reconcile + machine status. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: KKMachineSpec defines the desired state of KKMachine. + properties: + providerID: + description: ProviderID is the unique identifier as specified by the + kubekey provider. + type: string + roles: + description: Roles is the role of the machine, like `Worker`, `Master`, + `ControlPlane`, etc. + items: + type: string + type: array + type: object + status: + description: KKMachineStatus defines the observed state of KKMachine. + properties: + conditions: + description: Conditions defines current service state of the KKMachine. + items: + description: Condition defines an observation of a Cluster API resource + operational state. + properties: + lastTransitionTime: + description: |- + Last time the condition transitioned from one status to another. + This should be when the underlying condition changed. If that is not known, then using the time when + the API field changed is acceptable. + format: date-time + type: string + message: + description: |- + A human readable message indicating details about the transition. + This field may be empty. + type: string + reason: + description: |- + The reason for the condition's last transition in CamelCase. + The specific API may choose whether or not this field is considered a guaranteed API. + This field may not be empty. + type: string + severity: + description: |- + Severity provides an explicit classification of Reason code, so the users or machines can immediately + understand the current situation and act accordingly. + The Severity field MUST be set only when Status=False. + type: string + status: + description: Status of the condition, one of True, False, Unknown. + type: string + type: + description: |- + Type of condition in CamelCase or in foo.example.com/CamelCase. + Many .condition.type values are consistent across resources like Available, but because arbitrary conditions + can be useful (see .node.status.conditions), the ability to deconflict is important. + type: string + required: + - lastTransitionTime + - status + - type + type: object + type: array + failureMessage: + description: |- + FailureMessage will be set in the event that there is a terminal problem + reconciling the Machine and will contain a more verbose string suitable + for logging and human consumption. + + + This field should not be set for transitive errors that a controller + faces that are expected to be fixed automatically over + time (like service outages), but instead indicate that something is + fundamentally wrong with the Machine's spec or the configuration of + the controller, and that manual intervention is required. Examples + of terminal errors would be invalid combinations of settings in the + spec, values that are unsupported by the controller, or the + responsible controller itself being critically misconfigured. + + + Any transient errors that occur during the reconciliation of Machines + can be added as events to the Machine object and/or logged in the + controller's output. + type: string + failureReason: + description: |- + FailureReason will be set in the event that there is a terminal problem + reconciling the Machine and will contain a succinct value suitable + for machine interpretation. + + + This field should not be set for transitive errors that a controller + faces that are expected to be fixed automatically over + time (like service outages), but instead indicate that something is + fundamentally wrong with the Machine's spec or the configuration of + the controller, and that manual intervention is required. Examples + of terminal errors would be invalid combinations of settings in the + spec, values that are unsupported by the controller, or the + responsible controller itself being critically misconfigured. + + + Any transient errors that occur during the reconciliation of Machines + can be added as events to the Machine object and/or logged in the + controller's output. + type: string + phase: + description: Phase of KKMachine. + type: string + ready: + description: Ready is true when the provider resource is ready. + type: boolean + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/config/capkk/crds/infrastructure.cluster.x-k8s.io_kkmachinetemplates.yaml b/config/capkk/crds/infrastructure.cluster.x-k8s.io_kkmachinetemplates.yaml new file mode 100644 index 000000000..329f0227b --- /dev/null +++ b/config/capkk/crds/infrastructure.cluster.x-k8s.io_kkmachinetemplates.yaml @@ -0,0 +1,121 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.15.0 + labels: + cluster.x-k8s.io/v1beta1: v1beta1 + name: kkmachinetemplates.infrastructure.cluster.x-k8s.io +spec: + group: infrastructure.cluster.x-k8s.io + names: + categories: + - cluster-api + kind: KKMachineTemplate + listKind: KKMachineTemplateList + plural: kkmachinetemplates + shortNames: + - kkmt + singular: kkmachinetemplate + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Time duration since creation of KKMachineTemplate + jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1beta1 + schema: + openAPIV3Schema: + description: KKMachineTemplate is the Schema for the kkmachinetemplates API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: KKMachineTemplateSpec defines the desired state of KKMachineTemplate. + properties: + template: + description: KKMachineTemplateResource describes the data needed to + create a KKMachine from a template. + properties: + metadata: + description: |- + Standard object's metadata. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata + properties: + annotations: + additionalProperties: + type: string + description: |- + Annotations is an unstructured key value map stored with a resource that may be + set by external tools to store and retrieve arbitrary metadata. They are not + queryable and should be preserved when modifying objects. + More info: http://kubernetes.io/docs/user-guide/annotations + type: object + labels: + additionalProperties: + type: string + description: |- + Map of string keys and values that can be used to organize and categorize + (scope and select) objects. May match selectors of replication controllers + and services. + More info: http://kubernetes.io/docs/user-guide/labels + type: object + type: object + spec: + description: Spec is the specification of the desired behavior + of the machine. + properties: + providerID: + description: ProviderID is the unique identifier as specified + by the kubekey provider. + type: string + roles: + description: Roles is the role of the machine, like `Worker`, + `Master`, `ControlPlane`, etc. + items: + type: string + type: array + type: object + required: + - spec + type: object + required: + - template + type: object + status: + description: KKMachineTemplateStatus defines a status for an KKMachineTemplate. + properties: + capacity: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: |- + Capacity defines the resource capacity for this machine. + This value is used for autoscaling from zero operations as defined in: + https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20210310-opt-in-autoscaling-from-zero.md + type: object + type: object + type: object + served: true + storage: true + subresources: {} diff --git a/pkg/apis/capkk/v1beta1/kkcluster_types.go b/pkg/apis/capkk/v1beta1/kkcluster_types.go new file mode 100644 index 000000000..24ccde277 --- /dev/null +++ b/pkg/apis/capkk/v1beta1/kkcluster_types.go @@ -0,0 +1,254 @@ +/* +Copyright 2024 The KubeSphere Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + "sigs.k8s.io/cluster-api/errors" +) + +// KKClusterPhase of KKCluster +type KKClusterPhase string + +// const defines current Phase of KKCluster. +const ( + KKClusterPhasePending KKClusterPhase = "Pending" + KKClusterPhaseSucceed KKClusterPhase = "Succeed" + KKClusterPhaseRunning KKClusterPhase = "Running" + KKClusterPhaseFailed KKClusterPhase = "Failed" +) + +// NodeSelectorMode defines selector function during select cluster nodes. +type NodeSelectorMode string + +// const defines various NodeSelectorMode of KKCluster. +const ( + RandomNodeSelectorMode NodeSelectorMode = "Random" + SequenceNodeSelectorMode NodeSelectorMode = "Sequence" + // ResponseTimeNodeSelectorMode NodeSelectorMode = "ResponseTime" +) + +const ( + // HostsReadyCondition will check if hosts are connected firstly, then select control-plane nodes and worker nodes. + HostsReadyCondition clusterv1.ConditionType = "HostsReadyCondition" + WaitingCheckHostReadyReason string = "WaitingForCheckHosts" + WaitingCheckHostReadyMessage string = "Waiting for check if all of the hosts are connected." + HostsNotReadyReason string = "HostsNotReady" + HostsSelectFailedMessage string = "Not enough connected hosts to complete host selection." + WaitingHostsSelectReason string = "WaitingForHostsSelect" + WaitingHostsSelectMessage string = "Waiting for select kube-control-plane and worker nodes." + HostsReadyReason string = "HostsReady" + HostsReadyMessage string = "All hosts are connected." + + // PreparationReadyCondition will check which artifacts need to be installed, also initialize the os system. + PreparationReadyCondition clusterv1.ConditionType = "PreCheckReadyCondition" + WaitingPreparationReason string = "WaitingForPreparation" + WaitingPreparationMessage string = "Waiting for pre-check and pre-install artifacts and initialize os system" + PreparationNotReadyReason string = "PreparationNotReady" + PreparationReadyReason string = "PreparationReady" + PreparationReadyMessage string = "Both artifacts pre-install and os initialization are ready." + + // EtcdReadyCondition will install etcd into etcd group (binary install only currently). + EtcdReadyCondition clusterv1.ConditionType = "EtcdReadyCondition" + WaitingInstallEtcdReason string = "WaitingForInstallEtcd" + WaitingInstallEtcdMessage string = "Waiting for install ETCD binary service" + EtcdNotReadyReason string = "ETCDNotReady" + EtcdReadyReason string = "EtcdReady" + EtcdReadyMessage string = "Etcd successfully installed." + + // BinaryInstallCondition will install cluster binary tools. + BinaryInstallCondition clusterv1.ConditionType = "BinaryInstallCondition" + WaitingInstallClusterBinaryReason string = "WaitingForInstallClusterBinary" + WaitingInstallClusterBinaryMessage string = "Waiting for install cluster binary tools, e.g. kubeadm and kubelet, etc." + BinaryNotReadyReason string = "ClusterBinaryNotReady" + BinaryReadyReason string = "ClusterBinaryReady" + BinaryReadyMessage string = "Cluster binary successfully installed" + + // BootstrapReadyCondition will execute `kubeadm join` & `kubeadm init` command. + BootstrapReadyCondition clusterv1.ConditionType = "BootstrapReadyCondition" + WaitingCheckBootstrapReadyReason string = "WaitingForBootstrapReady" + WaitingCheckBootstrapReadyMessage string = "Waiting for the initial bootstrap to complete. Adding control plane and worker nodes to the cluster." + BootstrapNotReadyReason string = "CheckBootstrapNotReady" + BootstrapReadyReason string = "CheckBootstrapReady" + BootstrapReadyMessage string = "Bootstrap is ready." + + // ClusterReadyCondition will check if cluster is ready. + ClusterReadyCondition clusterv1.ConditionType = "ClusterReadyCondition" + WaitingCheckClusterReadyReason string = "WaitingForClusterReady" + WaitingCheckClusterReadyMessage string = "Waiting for initial bootstrap to ready, add control-plane and worker nodes into cluster." + ClusterNotReadyReason string = "ClusterNotReady" + ClusterReadyReason string = "ClusterReady" + ClusterReadyMessage string = "Cluster is ready." +) + +const ( + // ClusterFinalizer allows ReconcileKKCluster to clean up KK resources associated with KKCluster before + // removing it from the apiserver. + ClusterFinalizer = "kkcluster.infrastructure.cluster.x-k8s.io" + + // DefaultNodeSelectorMode is select nodes randomly. + DefaultNodeSelectorMode = RandomNodeSelectorMode + + // DefaultControlPlaneGroupName defines default control plane group name of the kubernetes cluster. + DefaultControlPlaneGroupName = "kube_control_plane" + + // DefaultWorkerGroupName defines default worker group name of the kubernetes cluster. + DefaultWorkerGroupName = "kube_worker" + + // DefaultClusterGroupName defines default cluster group name of the kubernetes cluster. + DefaultClusterGroupName = "k8s_cluster" +) + +// KKClusterSpec defines the desired state of KKCluster. +type KKClusterSpec struct { + // Distribution represents the Kubernetes distribution type of the cluster. + Distribution string `json:"distribution,omitempty"` + + // NodeSelectorMode is the select mode of the node selector. + // +optional + NodeSelectorMode NodeSelectorMode `json:"nodeSelectorMode,omitempty"` + + // ControlPlaneGroupName is the group name of kubernetes control plane nodes. + // +optional + ControlPlaneGroupName string `json:"controlPlaneGroupName,omitempty"` + + // WorkerGroupName is the group name of kubernetes worker nodes. + // +optional + WorkerGroupName string `json:"workerGroupName,omitempty"` + + // ClusterGroupName is the group name of kubernetes cluster, which contains control plane group and worker group. + // +optional + ClusterGroupName string `json:"clusterGroupName,omitempty"` + + // InventoryRef is the reference of Inventory. + InventoryRef *corev1.ObjectReference `json:"inventoryRef,omitempty"` + + // ConfigRef is the reference of Config. + // +optional + ConfigRef *corev1.ObjectReference `json:"configRef,omitempty"` + + // ConfigRef is the reference of Pipeline. + PipelineRef *corev1.ObjectReference `json:"pipelineRef,omitempty"` + + // ControlPlaneLoadBalancer is optional configuration for customizing control plane behavior. + // +optional + ControlPlaneLoadBalancer *KKLoadBalancerSpec `json:"controlPlaneLoadBalancer,omitempty"` + + // ControlPlaneEndpoint represents the endpoint used to communicate with the control plane. + ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"` +} + +// KKClusterStatus defines the observed state of KKCluster. +type KKClusterStatus struct { + // +kubebuilder:default=false + Ready bool `json:"ready"` + + // Phase of KKCluster. + Phase KKClusterPhase `json:"phase,omitempty"` + + // FailureReason will be set in the event that there is a terminal problem + // reconciling the Machine and will contain a succinct value suitable + // for machine interpretation. + // + // This field should not be set for transitive errors that a controller + // faces that are expected to be fixed automatically over + // time (like service outages), but instead indicate that something is + // fundamentally wrong with the Machine's spec or the configuration of + // the controller, and that manual intervention is required. Examples + // of terminal errors would be invalid combinations of settings in the + // spec, values that are unsupported by the controller, or the + // responsible controller itself being critically misconfigured. + // + // Any transient errors that occur during the reconciliation of Machines + // can be added as events to the Machine object and/or logged in the + // controller's output. + // +optional + FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"` + + // FailureMessage will be set in the event that there is a terminal problem + // reconciling the Machine and will contain a more verbose string suitable + // for logging and human consumption. + // + // This field should not be set for transitive errors that a controller + // faces that are expected to be fixed automatically over + // time (like service outages), but instead indicate that something is + // fundamentally wrong with the Machine's spec or the configuration of + // the controller, and that manual intervention is required. Examples + // of terminal errors would be invalid combinations of settings in the + // spec, values that are unsupported by the controller, or the + // responsible controller itself being critically misconfigured. + // + // Any transient errors that occur during the reconciliation of Machines + // can be added as events to the Machine object and/or logged in the + // controller's output. + // +optional + FailureMessage *string `json:"failureMessage,omitempty"` + + // Conditions defines current service state of the KKCluster. + // +optional + Conditions clusterv1.Conditions `json:"conditions,omitempty"` +} + +// KKLoadBalancerSpec defines the desired state of an KK load balancer. +type KKLoadBalancerSpec struct { + // The hostname on which the API server is serving. + Host string `json:"host,omitempty"` +} + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +k8s:openapi-gen=true +// +kubebuilder:resource:scope=Namespaced,categories=cluster-api,shortName=kkc +// +kubebuilder:subresource:status +// +kubebuilder:metadata:labels="cluster.x-k8s.io/v1beta1=v1beta1" +// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this KKClusters belongs" +// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Cluster infrastructure is ready for SSH instances" +// +kubebuilder:printcolumn:name="Endpoint",type="string",JSONPath=".spec.controlPlaneEndpoint",description="API Endpoint",priority=1 + +// KKCluster resource maps a kubernetes cluster, manage and reconcile cluster status. +type KKCluster struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec KKClusterSpec `json:"spec,omitempty"` + Status KKClusterStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// KKClusterList of KKCluster +type KKClusterList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []KKCluster `json:"items"` +} + +// GetConditions returns the observations of the operational state of the KKCluster resource. +func (k *KKCluster) GetConditions() clusterv1.Conditions { + return k.Status.Conditions +} + +// SetConditions sets the underlying service state of the KKCluster to the predescribed clusterv1.Conditions. +func (k *KKCluster) SetConditions(conditions clusterv1.Conditions) { + k.Status.Conditions = conditions +} + +func init() { + SchemeBuilder.Register(&KKCluster{}, &KKClusterList{}) +} diff --git a/pkg/apis/capkk/v1beta1/kkmachine_types.go b/pkg/apis/capkk/v1beta1/kkmachine_types.go new file mode 100644 index 000000000..0dc5663b1 --- /dev/null +++ b/pkg/apis/capkk/v1beta1/kkmachine_types.go @@ -0,0 +1,135 @@ +/* +Copyright 2024 The KubeSphere Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + "sigs.k8s.io/cluster-api/errors" +) + +// KKMachinePhase of KKMachine +type KKMachinePhase string + +// const defines current Phase of KKMachine. +const ( + KKMachinePhasePending KKMachinePhase = "Pending" + KKMachinePhaseSucceed KKMachinePhase = "Succeed" + KKMachinePhaseRunning KKMachinePhase = "Running" + KKMachinePhaseFailed KKMachinePhase = "Failed" +) + +const ( + WORKER_ROLE string = "worker" + CONTROL_PLANE_ROLE string = "control-plane" + // MachineFinalizer allows ReconcileKKMachine to clean up KubeKey resources associated with KKMachine before + // removing it from the apiserver. + MachineFinalizer = "kkmachine.infrastructure.cluster.x-k8s.io" +) + +// KKMachineSpec defines the desired state of KKMachine. +type KKMachineSpec struct { + // ProviderID is the unique identifier as specified by the kubekey provider. + ProviderID *string `json:"providerID,omitempty"` + // Roles is the role of the machine, like `Worker`, `Master`, `ControlPlane`, etc. + // +optional + Roles []string `json:"roles"` +} + +// KKMachineStatus defines the observed state of KKMachine. +type KKMachineStatus struct { + // Ready is true when the provider resource is ready. + // +optional + Ready bool `json:"ready"` + + // Phase of KKMachine. + Phase KKMachinePhase `json:"phase,omitempty"` + + // FailureReason will be set in the event that there is a terminal problem + // reconciling the Machine and will contain a succinct value suitable + // for machine interpretation. + // + // This field should not be set for transitive errors that a controller + // faces that are expected to be fixed automatically over + // time (like service outages), but instead indicate that something is + // fundamentally wrong with the Machine's spec or the configuration of + // the controller, and that manual intervention is required. Examples + // of terminal errors would be invalid combinations of settings in the + // spec, values that are unsupported by the controller, or the + // responsible controller itself being critically misconfigured. + // + // Any transient errors that occur during the reconciliation of Machines + // can be added as events to the Machine object and/or logged in the + // controller's output. + // +optional + FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"` + + // FailureMessage will be set in the event that there is a terminal problem + // reconciling the Machine and will contain a more verbose string suitable + // for logging and human consumption. + // + // This field should not be set for transitive errors that a controller + // faces that are expected to be fixed automatically over + // time (like service outages), but instead indicate that something is + // fundamentally wrong with the Machine's spec or the configuration of + // the controller, and that manual intervention is required. Examples + // of terminal errors would be invalid combinations of settings in the + // spec, values that are unsupported by the controller, or the + // responsible controller itself being critically misconfigured. + // + // Any transient errors that occur during the reconciliation of Machines + // can be added as events to the Machine object and/or logged in the + // controller's output. + // +optional + FailureMessage *string `json:"failureMessage,omitempty"` + + // Conditions defines current service state of the KKMachine. + // +optional + Conditions clusterv1.Conditions `json:"conditions,omitempty"` +} + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +k8s:openapi-gen=true +// +kubebuilder:resource:scope=Namespaced,categories=cluster-api,shortName=kkm +// +kubebuilder:subresource:status +// +kubebuilder:metadata:labels="cluster.x-k8s.io/v1beta1=v1beta1" +// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this KKMachine belongs" +// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Machine ready status" +// +kubebuilder:printcolumn:name="Machine",type="string",JSONPath=".metadata.ownerReferences[?(@.kind==\"Machine\")].name",description="Machine object which owns with this KKMachine" + +// KKMachine resource maps a machine instance, manage and reconcile machine status. +type KKMachine struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec KKMachineSpec `json:"spec,omitempty"` + Status KKMachineStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// KKMachineList of KKMachine +type KKMachineList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []KKMachine `json:"items"` +} + +func init() { + SchemeBuilder.Register(&KKMachine{}, &KKMachineList{}) +} diff --git a/pkg/apis/capkk/v1beta1/kkmachinetemplate_types.go b/pkg/apis/capkk/v1beta1/kkmachinetemplate_types.go new file mode 100644 index 000000000..e512df381 --- /dev/null +++ b/pkg/apis/capkk/v1beta1/kkmachinetemplate_types.go @@ -0,0 +1,77 @@ +/* +Copyright 2024 The KubeSphere Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" +) + +// KKMachineTemplateStatus defines a status for an KKMachineTemplate. +type KKMachineTemplateStatus struct { + // Capacity defines the resource capacity for this machine. + // This value is used for autoscaling from zero operations as defined in: + // https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20210310-opt-in-autoscaling-from-zero.md + // +optional + Capacity corev1.ResourceList `json:"capacity,omitempty"` +} + +// KKMachineTemplateSpec defines the desired state of KKMachineTemplate. +type KKMachineTemplateSpec struct { + Template KKMachineTemplateResource `json:"template"` +} + +// KKMachineTemplateResource describes the data needed to create a KKMachine from a template. +type KKMachineTemplateResource struct { + // Standard object's metadata. + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata + // +optional + ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"` + + // Spec is the specification of the desired behavior of the machine. + Spec KKMachineSpec `json:"spec"` +} + +// +kubebuilder:object:root=true +// +kubebuilder:resource:path=kkmachinetemplates,scope=Namespaced,categories=cluster-api,shortName=kkmt +// +kubebuilder:storageversion +// +kubebuilder:metadata:labels="cluster.x-k8s.io/v1beta1=v1beta1" +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of KKMachineTemplate" +// +k8s:defaulter-gen=true + +// KKMachineTemplate is the Schema for the kkmachinetemplates API +type KKMachineTemplate struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec KKMachineTemplateSpec `json:"spec,omitempty"` + Status KKMachineTemplateStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// KKMachineTemplateList contains a list of KKMachineTemplate +type KKMachineTemplateList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []KKMachineTemplate `json:"items"` +} + +func init() { + SchemeBuilder.Register(&KKMachineTemplate{}, &KKMachineTemplateList{}) +} diff --git a/pkg/apis/capkk/v1beta1/register.go b/pkg/apis/capkk/v1beta1/register.go new file mode 100644 index 000000000..701ae5c3c --- /dev/null +++ b/pkg/apis/capkk/v1beta1/register.go @@ -0,0 +1,36 @@ +/* +Copyright 2023 The KubeSphere Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package v1 contains API Schema definitions for the kubekey v1 API group +// +k8s:deepcopy-gen=package,register +// +groupName=infrastructure.cluster.x-k8s.io +package v1beta1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // SchemeGroupVersion is group version used to register these objects + SchemeGroupVersion = schema.GroupVersion{Group: "infrastructure.cluster.x-k8s.io", Version: "v1beta1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/pkg/apis/capkk/v1beta1/zz_generated.deepcopy.go b/pkg/apis/capkk/v1beta1/zz_generated.deepcopy.go new file mode 100644 index 000000000..2f7e9e521 --- /dev/null +++ b/pkg/apis/capkk/v1beta1/zz_generated.deepcopy.go @@ -0,0 +1,400 @@ +//go:build !ignore_autogenerated + +/* +Copyright 2023 The KubeSphere Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" + apiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" + "sigs.k8s.io/cluster-api/errors" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKCluster) DeepCopyInto(out *KKCluster) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKCluster. +func (in *KKCluster) DeepCopy() *KKCluster { + if in == nil { + return nil + } + out := new(KKCluster) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KKCluster) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKClusterList) DeepCopyInto(out *KKClusterList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]KKCluster, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKClusterList. +func (in *KKClusterList) DeepCopy() *KKClusterList { + if in == nil { + return nil + } + out := new(KKClusterList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KKClusterList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKClusterSpec) DeepCopyInto(out *KKClusterSpec) { + *out = *in + if in.InventoryRef != nil { + in, out := &in.InventoryRef, &out.InventoryRef + *out = new(v1.ObjectReference) + **out = **in + } + if in.ConfigRef != nil { + in, out := &in.ConfigRef, &out.ConfigRef + *out = new(v1.ObjectReference) + **out = **in + } + if in.PipelineRef != nil { + in, out := &in.PipelineRef, &out.PipelineRef + *out = new(v1.ObjectReference) + **out = **in + } + if in.ControlPlaneLoadBalancer != nil { + in, out := &in.ControlPlaneLoadBalancer, &out.ControlPlaneLoadBalancer + *out = new(KKLoadBalancerSpec) + **out = **in + } + out.ControlPlaneEndpoint = in.ControlPlaneEndpoint +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKClusterSpec. +func (in *KKClusterSpec) DeepCopy() *KKClusterSpec { + if in == nil { + return nil + } + out := new(KKClusterSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKClusterStatus) DeepCopyInto(out *KKClusterStatus) { + *out = *in + if in.FailureReason != nil { + in, out := &in.FailureReason, &out.FailureReason + *out = new(errors.MachineStatusError) + **out = **in + } + if in.FailureMessage != nil { + in, out := &in.FailureMessage, &out.FailureMessage + *out = new(string) + **out = **in + } + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make(apiv1beta1.Conditions, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKClusterStatus. +func (in *KKClusterStatus) DeepCopy() *KKClusterStatus { + if in == nil { + return nil + } + out := new(KKClusterStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKLoadBalancerSpec) DeepCopyInto(out *KKLoadBalancerSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKLoadBalancerSpec. +func (in *KKLoadBalancerSpec) DeepCopy() *KKLoadBalancerSpec { + if in == nil { + return nil + } + out := new(KKLoadBalancerSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKMachine) DeepCopyInto(out *KKMachine) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKMachine. +func (in *KKMachine) DeepCopy() *KKMachine { + if in == nil { + return nil + } + out := new(KKMachine) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KKMachine) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKMachineList) DeepCopyInto(out *KKMachineList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]KKMachine, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKMachineList. +func (in *KKMachineList) DeepCopy() *KKMachineList { + if in == nil { + return nil + } + out := new(KKMachineList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KKMachineList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKMachineSpec) DeepCopyInto(out *KKMachineSpec) { + *out = *in + if in.ProviderID != nil { + in, out := &in.ProviderID, &out.ProviderID + *out = new(string) + **out = **in + } + if in.Roles != nil { + in, out := &in.Roles, &out.Roles + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKMachineSpec. +func (in *KKMachineSpec) DeepCopy() *KKMachineSpec { + if in == nil { + return nil + } + out := new(KKMachineSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKMachineStatus) DeepCopyInto(out *KKMachineStatus) { + *out = *in + if in.FailureReason != nil { + in, out := &in.FailureReason, &out.FailureReason + *out = new(errors.MachineStatusError) + **out = **in + } + if in.FailureMessage != nil { + in, out := &in.FailureMessage, &out.FailureMessage + *out = new(string) + **out = **in + } + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make(apiv1beta1.Conditions, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKMachineStatus. +func (in *KKMachineStatus) DeepCopy() *KKMachineStatus { + if in == nil { + return nil + } + out := new(KKMachineStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKMachineTemplate) DeepCopyInto(out *KKMachineTemplate) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKMachineTemplate. +func (in *KKMachineTemplate) DeepCopy() *KKMachineTemplate { + if in == nil { + return nil + } + out := new(KKMachineTemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KKMachineTemplate) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKMachineTemplateList) DeepCopyInto(out *KKMachineTemplateList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]KKMachineTemplate, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKMachineTemplateList. +func (in *KKMachineTemplateList) DeepCopy() *KKMachineTemplateList { + if in == nil { + return nil + } + out := new(KKMachineTemplateList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KKMachineTemplateList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKMachineTemplateResource) DeepCopyInto(out *KKMachineTemplateResource) { + *out = *in + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKMachineTemplateResource. +func (in *KKMachineTemplateResource) DeepCopy() *KKMachineTemplateResource { + if in == nil { + return nil + } + out := new(KKMachineTemplateResource) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKMachineTemplateSpec) DeepCopyInto(out *KKMachineTemplateSpec) { + *out = *in + in.Template.DeepCopyInto(&out.Template) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKMachineTemplateSpec. +func (in *KKMachineTemplateSpec) DeepCopy() *KKMachineTemplateSpec { + if in == nil { + return nil + } + out := new(KKMachineTemplateSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KKMachineTemplateStatus) DeepCopyInto(out *KKMachineTemplateStatus) { + *out = *in + if in.Capacity != nil { + in, out := &in.Capacity, &out.Capacity + *out = make(v1.ResourceList, len(*in)) + for key, val := range *in { + (*out)[key] = val.DeepCopy() + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KKMachineTemplateStatus. +func (in *KKMachineTemplateStatus) DeepCopy() *KKMachineTemplateStatus { + if in == nil { + return nil + } + out := new(KKMachineTemplateStatus) + in.DeepCopyInto(out) + return out +} From 7d9a4175bd72719e5abe5632c11603e48b349fb8 Mon Sep 17 00:00:00 2001 From: DingYongliang <1521323439@qq.com> Date: Wed, 18 Sep 2024 18:16:31 +0800 Subject: [PATCH 2/2] feat: add annotations for CRDs --- pkg/apis/capkk/v1beta1/kkcluster_types.go | 109 ++++++++++++++-------- pkg/apis/capkk/v1beta1/kkmachine_types.go | 6 +- 2 files changed, 75 insertions(+), 40 deletions(-) diff --git a/pkg/apis/capkk/v1beta1/kkcluster_types.go b/pkg/apis/capkk/v1beta1/kkcluster_types.go index 24ccde277..c37a48071 100644 --- a/pkg/apis/capkk/v1beta1/kkcluster_types.go +++ b/pkg/apis/capkk/v1beta1/kkcluster_types.go @@ -46,55 +46,88 @@ const ( const ( // HostsReadyCondition will check if hosts are connected firstly, then select control-plane nodes and worker nodes. - HostsReadyCondition clusterv1.ConditionType = "HostsReadyCondition" - WaitingCheckHostReadyReason string = "WaitingForCheckHosts" - WaitingCheckHostReadyMessage string = "Waiting for check if all of the hosts are connected." - HostsNotReadyReason string = "HostsNotReady" - HostsSelectFailedMessage string = "Not enough connected hosts to complete host selection." - WaitingHostsSelectReason string = "WaitingForHostsSelect" - WaitingHostsSelectMessage string = "Waiting for select kube-control-plane and worker nodes." - HostsReadyReason string = "HostsReady" - HostsReadyMessage string = "All hosts are connected." + HostsReadyCondition clusterv1.ConditionType = "HostsReadyCondition" + // WaitingCheckHostReadyReason is one `Reason` of HostsReadyCondition. + WaitingCheckHostReadyReason string = "WaitingForCheckHosts" + // WaitingCheckHostReadyMessage is a specification `Message` of WaitingCheckHostReadyReason. + WaitingCheckHostReadyMessage string = "Waiting for check if all of the hosts are connected." + // HostsNotReadyReason is one `Reason` of HostsReadyCondition. + HostsNotReadyReason string = "HostsNotReady" + // HostsSelectFailedMessage is a specification `Message` of HostsNotReadyReason. + HostsSelectFailedMessage string = "Not enough connected hosts to complete host selection." + // WaitingHostsSelectReason is one `Reason` of HostsReadyCondition. + WaitingHostsSelectReason string = "WaitingForHostsSelect" + // WaitingHostsSelectMessage is a specification `Message` of HostsNotReadyReason. + WaitingHostsSelectMessage string = "Waiting for select kube-control-plane and worker nodes." + // HostsReadyReason is one `Reason` of HostsReadyCondition. + HostsReadyReason string = "HostsReady" + // HostsReadyMessage is a specification `Message` of HostsNotReadyReason. + HostsReadyMessage string = "All hosts are connected." // PreparationReadyCondition will check which artifacts need to be installed, also initialize the os system. PreparationReadyCondition clusterv1.ConditionType = "PreCheckReadyCondition" - WaitingPreparationReason string = "WaitingForPreparation" - WaitingPreparationMessage string = "Waiting for pre-check and pre-install artifacts and initialize os system" - PreparationNotReadyReason string = "PreparationNotReady" - PreparationReadyReason string = "PreparationReady" - PreparationReadyMessage string = "Both artifacts pre-install and os initialization are ready." + // WaitingPreparationReason is one `Reason` of PreparationReadyCondition. + WaitingPreparationReason string = "WaitingForPreparation" + // WaitingPreparationMessage is a specification `Message` of PreparationReadyCondition. + WaitingPreparationMessage string = "Waiting for pre-check and pre-install artifacts and initialize os system" + // PreparationNotReadyReason is one `Reason` of PreparationReadyCondition. + PreparationNotReadyReason string = "PreparationNotReady" + // PreparationReadyReason is one `Reason` of PreparationReadyCondition. + PreparationReadyReason string = "PreparationReady" + // PreparationReadyMessage is a specification `Message` of PreparationReadyCondition. + PreparationReadyMessage string = "Both artifacts pre-install and os initialization are ready." // EtcdReadyCondition will install etcd into etcd group (binary install only currently). - EtcdReadyCondition clusterv1.ConditionType = "EtcdReadyCondition" - WaitingInstallEtcdReason string = "WaitingForInstallEtcd" - WaitingInstallEtcdMessage string = "Waiting for install ETCD binary service" - EtcdNotReadyReason string = "ETCDNotReady" - EtcdReadyReason string = "EtcdReady" - EtcdReadyMessage string = "Etcd successfully installed." + EtcdReadyCondition clusterv1.ConditionType = "EtcdReadyCondition" + // WaitingInstallEtcdReason is one `Reason` of EtcdReadyCondition. + WaitingInstallEtcdReason string = "WaitingForInstallEtcd" + // WaitingInstallEtcdMessage is a specification `Message` of EtcdReadyCondition. + WaitingInstallEtcdMessage string = "Waiting for install ETCD binary service" + // EtcdNotReadyReason is one `Reason` of EtcdReadyCondition. + EtcdNotReadyReason string = "ETCDNotReady" + // EtcdReadyReason is one `Reason` of EtcdReadyCondition. + EtcdReadyReason string = "EtcdReady" + // EtcdReadyMessage is a specification `Message` of EtcdReadyCondition. + EtcdReadyMessage string = "Etcd successfully installed." // BinaryInstallCondition will install cluster binary tools. - BinaryInstallCondition clusterv1.ConditionType = "BinaryInstallCondition" - WaitingInstallClusterBinaryReason string = "WaitingForInstallClusterBinary" - WaitingInstallClusterBinaryMessage string = "Waiting for install cluster binary tools, e.g. kubeadm and kubelet, etc." - BinaryNotReadyReason string = "ClusterBinaryNotReady" - BinaryReadyReason string = "ClusterBinaryReady" - BinaryReadyMessage string = "Cluster binary successfully installed" + BinaryInstallCondition clusterv1.ConditionType = "BinaryInstallCondition" + // WaitingInstallClusterBinaryReason is one `Reason` of BinaryInstallCondition. + WaitingInstallClusterBinaryReason string = "WaitingForInstallClusterBinary" + // WaitingInstallClusterBinaryMessage is a specification `Message` of BinaryInstallCondition. + WaitingInstallClusterBinaryMessage string = "Waiting for install cluster binary tools, e.g. kubeadm and kubelet, etc." + // BinaryNotReadyReason is one `Reason` of BinaryInstallCondition. + BinaryNotReadyReason string = "ClusterBinaryNotReady" + // BinaryReadyReason is one `Reason` of BinaryInstallCondition. + BinaryReadyReason string = "ClusterBinaryReady" + // BinaryReadyMessage is a specification `Message` of BinaryInstallCondition. + BinaryReadyMessage string = "Cluster binary successfully installed" // BootstrapReadyCondition will execute `kubeadm join` & `kubeadm init` command. - BootstrapReadyCondition clusterv1.ConditionType = "BootstrapReadyCondition" - WaitingCheckBootstrapReadyReason string = "WaitingForBootstrapReady" - WaitingCheckBootstrapReadyMessage string = "Waiting for the initial bootstrap to complete. Adding control plane and worker nodes to the cluster." - BootstrapNotReadyReason string = "CheckBootstrapNotReady" - BootstrapReadyReason string = "CheckBootstrapReady" - BootstrapReadyMessage string = "Bootstrap is ready." + BootstrapReadyCondition clusterv1.ConditionType = "BootstrapReadyCondition" + // WaitingCheckBootstrapReadyReason is one `Reason` of BootstrapReadyCondition. + WaitingCheckBootstrapReadyReason string = "WaitingForBootstrapReady" + // WaitingCheckBootstrapReadyMessage is a specification `Message` of BootstrapReadyCondition. + WaitingCheckBootstrapReadyMessage string = "Waiting for the initial bootstrap to complete. Adding control plane and worker nodes to the cluster." + // BootstrapNotReadyReason is one `Reason` of BootstrapReadyCondition. + BootstrapNotReadyReason string = "CheckBootstrapNotReady" + // BootstrapReadyReason is one `Reason` of BootstrapReadyCondition. + BootstrapReadyReason string = "CheckBootstrapReady" + // BootstrapReadyMessage is a specification `Message` of BootstrapReadyCondition. + BootstrapReadyMessage string = "Bootstrap is ready." // ClusterReadyCondition will check if cluster is ready. - ClusterReadyCondition clusterv1.ConditionType = "ClusterReadyCondition" - WaitingCheckClusterReadyReason string = "WaitingForClusterReady" - WaitingCheckClusterReadyMessage string = "Waiting for initial bootstrap to ready, add control-plane and worker nodes into cluster." - ClusterNotReadyReason string = "ClusterNotReady" - ClusterReadyReason string = "ClusterReady" - ClusterReadyMessage string = "Cluster is ready." + ClusterReadyCondition clusterv1.ConditionType = "ClusterReadyCondition" + // WaitingCheckClusterReadyReason is one `Reason` of ClusterReadyCondition. + WaitingCheckClusterReadyReason string = "WaitingForClusterReady" + // WaitingCheckClusterReadyMessage is a specification `Message` of ClusterReadyCondition. + WaitingCheckClusterReadyMessage string = "Waiting for initial bootstrap to ready, add control-plane and worker nodes into cluster." + // ClusterNotReadyReason is one `Reason` of ClusterReadyCondition. + ClusterNotReadyReason string = "ClusterNotReady" + // ClusterReadyReason is one `Reason` of ClusterReadyCondition. + ClusterReadyReason string = "ClusterReady" + // ClusterReadyMessage is a specification `Message` of ClusterReadyCondition. + ClusterReadyMessage string = "Cluster is ready." ) const ( diff --git a/pkg/apis/capkk/v1beta1/kkmachine_types.go b/pkg/apis/capkk/v1beta1/kkmachine_types.go index 0dc5663b1..f560e4d14 100644 --- a/pkg/apis/capkk/v1beta1/kkmachine_types.go +++ b/pkg/apis/capkk/v1beta1/kkmachine_types.go @@ -34,8 +34,10 @@ const ( ) const ( - WORKER_ROLE string = "worker" - CONTROL_PLANE_ROLE string = "control-plane" + // WorkerRole defines worker node role. + WorkerRole string = "worker" + // ControlPlaneRole defines control plane node role. + ControlPlaneRole string = "control-plane" // MachineFinalizer allows ReconcileKKMachine to clean up KubeKey resources associated with KKMachine before // removing it from the apiserver. MachineFinalizer = "kkmachine.infrastructure.cluster.x-k8s.io"