Skip to content

Commit

Permalink
feat: kbcli builder cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
nashtsai committed Mar 28, 2023
1 parent ea34676 commit 43e10b7
Show file tree
Hide file tree
Showing 28 changed files with 19,528 additions and 125 deletions.
10 changes: 8 additions & 2 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ resources:
kind: ConfigConstraint
path: github.com/apecloud/kubeblocks/apis/apps/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: kubeblocks.io
group: apps
kind: ComponentsDiscovery
path: github.com/apecloud/kubeblocks/apis/apps/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
Expand All @@ -113,15 +121,13 @@ resources:
crdVersion: v1
namespaced: true
domain: troubleshoot.sh
group:
kind: HostPreflight
path: github.com/apecloud/kubeblocks/externalapis/preflight/v1beta2
version: v1beta2
- api:
crdVersion: v1
namespaced: true
domain: troubleshoot.sh
group:
kind: Preflight
path: github.com/apecloud/kubeblocks/externalapis/preflight/v1beta2
version: v1beta2
Expand Down
29 changes: 11 additions & 18 deletions apis/apps/v1alpha1/clusterdefinition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

// ClusterDefinitionSpec defines the desired state of ClusterDefinition
type ClusterDefinitionSpec struct {

// componentDefs provides cluster components definitions.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinItems=1
Expand All @@ -52,7 +51,6 @@ type ClusterDefinitionSpec struct {
ConnectionCredential map[string]string `json:"connectionCredential,omitempty"`
}

// SystemAccountSpec specifies information to create system accounts.
type SystemAccountSpec struct {
// cmdExecutorConfig configs how to get client SDK and perform statements.
// +kubebuilder:validation:Required
Expand All @@ -70,14 +68,11 @@ type SystemAccountSpec struct {
Accounts []SystemAccountConfig `json:"accounts" patchStrategy:"merge,retainKeys" patchMergeKey:"name"`
}

// CmdExecutorConfig specifies how to perform creation and deletion statements.
type CmdExecutorConfig struct {
CommandExecutorEnvItem `json:",inline"`

CommandExecutorItem `json:",inline"`
CommandExecutorItem `json:",inline"`
}

// PasswordConfig helps provide to customize complexity of password generation pattern.
type PasswordConfig struct {
// length defines the length of password.
// +kubebuilder:validation:Maximum=32
Expand Down Expand Up @@ -166,10 +161,6 @@ type ClusterDefinitionStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

func (r ClusterDefinitionStatus) GetTerminalPhases() []Phase {
return []Phase{AvailablePhase}
}

type ComponentTemplateSpec struct {
// Specify the name of configuration template.
// +kubebuilder:validation:Required
Expand Down Expand Up @@ -235,7 +226,6 @@ type ExporterConfig struct {
// +optional
ScrapePath string `json:"scrapePath,omitempty"`
}

type MonitorConfig struct {
// builtIn is a switch to enable KubeBlocks builtIn monitoring.
// If BuiltIn is set to false, the provider should set ExporterConfig and Sidecar container own.
Expand Down Expand Up @@ -277,16 +267,17 @@ type VolumeTypeSpec struct {
Type VolumeType `json:"type,omitempty"`
}

// ClusterComponentDefinition provides a workload component specification template,
// with attributes that strongly work with stateful workloads and day-2 operations
// behaviors.
type ClusterComponentDefinition struct {
// Name of the component, it can be any valid string.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MaxLength=18
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
Name string `json:"name"`

ClusterComponentDefinitionSpec `json:",inline"`
}

type ClusterComponentDefinitionSpec struct {
// The description of component definition.
// +optional
Description string `json:"description,omitempty"`
Expand Down Expand Up @@ -314,16 +305,15 @@ type ClusterComponentDefinition struct {

// The configSpec field provided by provider, and
// finally this configTemplateRefs will be rendered into the user's own configuration file according to the user's cluster.
// +optional
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=name
// +optional
ConfigSpecs []ComponentConfigSpec `json:"configSpecs,omitempty"`

// The scriptSpec field provided by provider, and
// finally this configTemplateRefs will be rendered into the user's own configuration file according to the user's cluster.
// +optional
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
// +listType=map
Expand All @@ -340,11 +330,11 @@ type ClusterComponentDefinition struct {
Monitor *MonitorConfig `json:"monitor,omitempty"`

// logConfigs is detail log file config which provided by provider.
// +optional
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=name
// +optional
LogConfigs []LogConfig `json:"logConfigs,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name"`

// podSpec define pod spec template of the cluster component.
Expand Down Expand Up @@ -448,7 +438,6 @@ type ClusterDefinitionProbe struct {
}

type ClusterDefinitionProbes struct {

// Probe for DB running check.
// +optional
RunningProbe *ClusterDefinitionProbe `json:"runningProbe,omitempty"`
Expand Down Expand Up @@ -663,3 +652,7 @@ func (r *ClusterDefinition) GetComponentDefByName(compDefName string) *ClusterCo
}
return nil
}

func (r ClusterDefinitionStatus) GetTerminalPhases() []Phase {
return []Phase{AvailablePhase}
}
157 changes: 157 additions & 0 deletions apis/apps/v1alpha1/componentsdiscovery_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
Copyright ApeCloud, Inc.
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 v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

extensionsv1alpha1 "github.com/apecloud/kubeblocks/apis/extensions/v1alpha1"
)

// ComponentsDiscoverySpec defines the desired state of ComponentsDiscovery
type ComponentsDiscoverySpec struct {
// Discovery type, valid values are Helm, Manifests, ExistingCluster.
// +kubebuilder:validation:Required
Type DiscoveryType `json:"type"`

// Helm discovery spec., it's only being processed if type=Helm.
// +optional
Helm *HelmDiscoverySpec `json:"helm,omitempty"`

// Manifest discovery spec., it's only being processed if type=Manifests.
// +optional
Manifests *ManifestsDiscoverySpec `json:"manifests,omitempty"`

// Cluster discovery spec., it's only being processed if type=Cluster.
// +optional
Cluster *ClusterDiscoverySpec `json:"cluster,omitempty"`

// componentDefSelectors defines clusterdefinition.spec.componentDefs[] override
// attributes, and workload related resources selectors.
// +optional
ComponentDefSelectors []ComponentDefSelector `json:"componentDefSelectors,omitempty"`
}

type ComponentDefSelector struct {
// Name of component definition.
// +kubebuilder:validation:Required
Name string `json:"name"`

// workloadSelector defines workload label selector, the selector will attempt to
// select 1st discovered statefulsets.apps, deployment.apps and set to
// workloadType=[stateful | stateless], only workload's `.spec.template.spec` is preserved.
// +optional
WorkloadSelector map[string]string `json:"workloadSelector,omitempty"`

// serviceSelector defines primary service label selector.
// +optional
ServiceSelector map[string]string `json:"serviceSelector,omitempty"`

// configsSelector defines primary config file configMap items label selector.
// +optional
ConfigsSelector map[string]string `json:"configsSelector,omitempty"`

// scriptsSelector defines script file configMap items label selector.
// +optional
ScriptsSelector map[string]string `json:"scriptsSelector,omitempty"`

// pdbSelector defines PodDistruptionBudget object selector to derive max maxUnavailable value.
// +optional
PDBSelector map[string]string `json:"pdbSelector,omitempty"`

// componentDefinitionOverride define override value for generating clusterdefinition.spec.componentDefs[] spec.ma
// +optional
ComponentDefinitionOverride *ClusterComponentDefinitionSpec `json:"componentDefinitionOverride,omitempty"`
}

type HelmDiscoverySpec struct {
// A Helm Chart location URL.
// +kubebuilder:validation:Required
ChartLocationURL string `json:"chartLocationURL"`

// installOptions defines Helm release install options.
// +optional
InstallOptions extensionsv1alpha1.HelmInstallOptions `json:"installOptions,omitempty"`

// HelmInstallValues defines Helm release install set values.
// +optional
InstallValues HelmInstallValues `json:"installValues,omitempty"`
}

type HelmInstallValues struct {
// valuesItems correspond to `helm install --values` flag, specify values in
// a YAML file or a URL (can specify multiple).
// +optional
ValuesItems []string `json:"valuesItems,omitempty"`

// setItems correspond to `helm install --set` flag, specify set values, can
// specify multiple or separate values with commas(key1=val1,key2=val2).
// +optional
SetValues []string `json:"setItems,omitempty"`

// setJSONItems correspond to `helm install --set-json` flag, specify set JSON values,
// can specify multiple or separate values with commas(key1=jsonval1,key2=jsonval2).
// +optional
SetJSONValues []string `json:"setJSONItems,omitempty"`
}

type ManifestsDiscoverySpec struct {
// A location URL, accept 'file://' protocol.
// +kubebuilder:validation:Required
LocationURL string `json:"chartLocationURL"`
}

type ClusterDiscoverySpec struct {
// +kubebuilder:validation:Required
Namespace string `json:"namespace"`
Selectors []ObjectSelector `json:"selectors"`
}

type ObjectSelector struct {
// gvk specify Group-Version-Kind API target to select, in syntax of <group>/<version>/<Kind>,
// or for group-less APIs in syntax of <version>/<Kind>.
// +kubebuilder:validation:Required
GVK string `json:"gvk"`

// selector is an object kind selector.
// Selector which must match objects' labels.
Selector map[string]string `json:"selector"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// ComponentsDiscovery is the Schema for the componentsdiscoveries API
type ComponentsDiscovery struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ComponentsDiscoverySpec `json:"spec,omitempty"`
}

//+kubebuilder:object:root=true

// ComponentsDiscoveryList contains a list of ComponentsDiscovery
type ComponentsDiscoveryList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ComponentsDiscovery `json:"items"`
}

func init() {
SchemeBuilder.Register(&ComponentsDiscovery{}, &ComponentsDiscoveryList{})
}
11 changes: 11 additions & 0 deletions apis/apps/v1alpha1/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,14 @@ const (
func RegisterWebhookManager(mgr manager.Manager) {
webhookMgr = &webhookManager{mgr.GetClient()}
}

// DiscoveryType defines component discovery type.
// +enum
// +kubebuilder:validation:Enum={Helm,Manifests,ExistingCluster}
type DiscoveryType string

const (
HelmDiscoveryType DiscoveryType = "Helm"
ManifestsDiscoveryType DiscoveryType = "Manifests"
ExistingClusterDiscoveryType DiscoveryType = "ExistingCluster"
)
4 changes: 2 additions & 2 deletions apis/extensions/v1alpha1/addon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ type AddonSpec struct {
// +optional
Description string `json:"description,omitempty"`

// Addon type, valid value is helm.
// Addon type, valid value is Helm.
// +kubebuilder:validation:Required
Type AddonType `json:"type"`

// Helm installation spec., it's only being processed if type=helm.
// Helm installation spec., it's only being processed if type=Helm.
// +optional
Helm *HelmTypeInstallSpec `json:"helm,omitempty"`

Expand Down
3 changes: 0 additions & 3 deletions config/crd/bases/apps.kubeblocks.io_clusterdefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ spec:
componentDefs:
description: componentDefs provides cluster components definitions.
items:
description: ClusterComponentDefinition provides a workload component
specification template, with attributes that strongly work with
stateful workloads and day-2 operations behaviors.
properties:
characterType:
description: characterType defines well-known database component
Expand Down
Loading

0 comments on commit 43e10b7

Please sign in to comment.