Skip to content

Commit

Permalink
Merge pull request K0rdent#381 from zerospiel/kbuilder_chores
Browse files Browse the repository at this point in the history
Kubebuilder API project chores
  • Loading branch information
Kshatrix authored Sep 24, 2024
2 parents a5e1920 + b8f72a2 commit a479f5e
Show file tree
Hide file tree
Showing 33 changed files with 372 additions and 305 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ AWSCLI ?= $(LOCALBIN)/aws
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.14.0
ENVTEST_VERSION ?= release-0.17
GOLANGCI_LINT_VERSION ?= v1.60.1
GOLANGCI_LINT_VERSION ?= v1.61.0
HELM_VERSION ?= v3.15.1
KIND_VERSION ?= v0.23.0
YQ_VERSION ?= v4.44.2
Expand Down
50 changes: 46 additions & 4 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
controller: true
domain: hmc.mirantis.com
group: hmc.mirantis.com
kind: Template
kind: ManagedCluster
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
- api:
Expand All @@ -23,7 +23,14 @@ resources:
controller: true
domain: hmc.mirantis.com
group: hmc.mirantis.com
kind: ManagedCluster
kind: Management
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
domain: hmc.mirantis.com
group: hmc.mirantis.com
kind: Release
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
- api:
Expand All @@ -32,14 +39,49 @@ resources:
controller: true
domain: hmc.mirantis.com
group: hmc.mirantis.com
kind: Management
kind: ClusterTemplate
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: hmc.mirantis.com
group: hmc.mirantis.com
kind: Release
kind: ProviderTemplate
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: hmc.mirantis.com
group: hmc.mirantis.com
kind: ServiceTemplate
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: hmc.mirantis.com
group: hmc.mirantis.com
kind: TemplateManagement
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: hmc.mirantis.com
group: hmc.mirantis.com
kind: ClusterTemplateChain
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
domain: hmc.mirantis.com
group: hmc.mirantis.com
kind: ServiceTemplateChain
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
version: "3"
39 changes: 22 additions & 17 deletions api/v1alpha1/clustertemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,38 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ClusterTemplateSpec defines the desired state of ClusterTemplate
type ClusterTemplateSpec struct {
TemplateSpecCommon `json:",inline"`
}

// ClusterTemplateStatus defines the observed state of ClusterTemplate
type ClusterTemplateStatus struct {
TemplateStatusCommon `json:",inline"`
}

func (t *ClusterTemplate) GetSpec() *TemplateSpecCommon {
return &t.Spec.TemplateSpecCommon
}

func (t *ClusterTemplate) GetStatus() *TemplateStatusCommon {
return &t.Status.TemplateStatusCommon
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=clustertmpl
// +kubebuilder:printcolumn:name="valid",type="boolean",JSONPath=".status.valid",description="Valid",priority=0
// +kubebuilder:printcolumn:name="validationError",type="string",JSONPath=".status.validationError",description="Validation Error",priority=1
// +kubebuilder:printcolumn:name="description",type="string",JSONPath=".status.description",description="Description",priority=1

// ClusterTemplate is the Schema for the cluster templates API
// ClusterTemplate is the Schema for the clustertemplates API
type ClusterTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable"

Spec ClusterTemplateSpec `json:"spec,omitempty"`
Status ClusterTemplateStatus `json:"status,omitempty"`
}
Expand All @@ -44,20 +63,6 @@ type ClusterTemplateList struct {
Items []ClusterTemplate `json:"items"`
}

// ClusterTemplateSpec defines the desired state of ClusterTemplate
type ClusterTemplateSpec struct {
TemplateSpecMixin `json:",inline"`
}

// ClusterTemplateStatus defines the observed state of ClusterTemplate
type ClusterTemplateStatus struct {
TemplateStatusMixin `json:",inline"`
}

func (t *ClusterTemplate) GetSpec() *TemplateSpecMixin {
return &t.Spec.TemplateSpecMixin
}

func (t *ClusterTemplate) GetStatus() *TemplateStatusMixin {
return &t.Status.TemplateStatusMixin
func init() {
SchemeBuilder.Register(&ClusterTemplate{}, &ClusterTemplateList{})
}
45 changes: 45 additions & 0 deletions api/v1alpha1/clustertemplatechain_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024
//
// 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"
)

// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster

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

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable"

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

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&ClusterTemplateChain{}, &ClusterTemplateChainList{})
}
20 changes: 9 additions & 11 deletions api/v1alpha1/managedcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,25 @@ const (

// ManagedClusterSpec defines the desired state of ManagedCluster
type ManagedClusterSpec struct {
// DryRun specifies whether the template should be applied after validation or only validated.
// +optional
DryRun bool `json:"dryRun,omitempty"`
// Template is a reference to a Template object located in the same namespace.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
Template string `json:"template"`
// Config allows to provide parameters for template customization.
// If no Config provided, the field will be populated with the default values for
// the template and DryRun will be enabled.
// +optional
Config *apiextensionsv1.JSON `json:"config,omitempty"`

// +kubebuilder:validation:MinLength=1

// Template is a reference to a Template object located in the same namespace.
Template string `json:"template"`
// DryRun specifies whether the template should be applied after validation or only validated.
DryRun bool `json:"dryRun,omitempty"`
}

// ManagedClusterStatus defines the observed state of ManagedCluster
type ManagedClusterStatus struct {
// ObservedGeneration is the last observed generation.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// Conditions contains details for the current state of the ManagedCluster
Conditions []metav1.Condition `json:"conditions,omitempty"`
// ObservedGeneration is the last observed generation.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
8 changes: 3 additions & 5 deletions api/v1alpha1/management_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ type Core struct {

// Component represents HMC management component
type Component struct {
// Template is the name of the Template associated with this component.
// If not specified, will be taken from the Release object.
Template string `json:"template,omitempty"`
// Config allows to provide parameters for management component customization.
// If no Config provided, the field will be populated with the default
// values for the template.
// +optional
Config *apiextensionsv1.JSON `json:"config,omitempty"`
// Template is the name of the Template associated with this component.
// If not specified, will be taken from the Release object.
Template string `json:"template,omitempty"`
}

type Provider struct {
Expand Down Expand Up @@ -88,7 +87,6 @@ func (m *ManagementSpec) SetProvidersDefaults() error {
// ManagementStatus defines the observed state of Management
type ManagementStatus struct {
// ObservedGeneration is the last observed generation.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// AvailableProviders holds all CAPI providers available on the Management cluster.
AvailableProviders Providers `json:"availableProviders,omitempty"`
Expand Down
39 changes: 22 additions & 17 deletions api/v1alpha1/providertemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,38 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ProviderTemplateSpec defines the desired state of ProviderTemplate
type ProviderTemplateSpec struct {
TemplateSpecCommon `json:",inline"`
}

// ProviderTemplateStatus defines the observed state of ProviderTemplate
type ProviderTemplateStatus struct {
TemplateStatusCommon `json:",inline"`
}

func (t *ProviderTemplate) GetSpec() *TemplateSpecCommon {
return &t.Spec.TemplateSpecCommon
}

func (t *ProviderTemplate) GetStatus() *TemplateStatusCommon {
return &t.Status.TemplateStatusCommon
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=providertmpl,scope=Cluster
// +kubebuilder:printcolumn:name="valid",type="boolean",JSONPath=".status.valid",description="Valid",priority=0
// +kubebuilder:printcolumn:name="validationError",type="string",JSONPath=".status.validationError",description="Validation Error",priority=1
// +kubebuilder:printcolumn:name="description",type="string",JSONPath=".status.description",description="Description",priority=1

// ProviderTemplate is the Schema for the provider templates API
// ProviderTemplate is the Schema for the providertemplates API
type ProviderTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable"

Spec ProviderTemplateSpec `json:"spec,omitempty"`
Status ProviderTemplateStatus `json:"status,omitempty"`
}
Expand All @@ -44,20 +63,6 @@ type ProviderTemplateList struct {
Items []ProviderTemplate `json:"items"`
}

// ProviderTemplateSpec defines the desired state of ProviderTemplate
type ProviderTemplateSpec struct {
TemplateSpecMixin `json:",inline"`
}

// ProviderTemplateStatus defines the observed state of ProviderTemplate
type ProviderTemplateStatus struct {
TemplateStatusMixin `json:",inline"`
}

func (t *ProviderTemplate) GetSpec() *TemplateSpecMixin {
return &t.Spec.TemplateSpecMixin
}

func (t *ProviderTemplate) GetStatus() *TemplateStatusMixin {
return &t.Status.TemplateStatusMixin
func init() {
SchemeBuilder.Register(&ProviderTemplate{}, &ProviderTemplateList{})
}
39 changes: 22 additions & 17 deletions api/v1alpha1/servicetemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,38 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ServiceTemplateSpec defines the desired state of ServiceTemplate
type ServiceTemplateSpec struct {
TemplateSpecCommon `json:",inline"`
}

// ServiceTemplateStatus defines the observed state of ServiceTemplate
type ServiceTemplateStatus struct {
TemplateStatusCommon `json:",inline"`
}

func (t *ServiceTemplate) GetSpec() *TemplateSpecCommon {
return &t.Spec.TemplateSpecCommon
}

func (t *ServiceTemplate) GetStatus() *TemplateStatusCommon {
return &t.Status.TemplateStatusCommon
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=svctmpl
// +kubebuilder:printcolumn:name="valid",type="boolean",JSONPath=".status.valid",description="Valid",priority=0
// +kubebuilder:printcolumn:name="validationError",type="string",JSONPath=".status.validationError",description="Validation Error",priority=1
// +kubebuilder:printcolumn:name="description",type="string",JSONPath=".status.description",description="Description",priority=1

// ServiceTemplate is the Schema for the service templates API
// ServiceTemplate is the Schema for the servicetemplates API
type ServiceTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable"

Spec ServiceTemplateSpec `json:"spec,omitempty"`
Status ServiceTemplateStatus `json:"status,omitempty"`
}
Expand All @@ -44,20 +63,6 @@ type ServiceTemplateList struct {
Items []ServiceTemplate `json:"items"`
}

// ServiceTemplateSpec defines the desired state of ServiceTemplate
type ServiceTemplateSpec struct {
TemplateSpecMixin `json:",inline"`
}

// ServiceTemplateStatus defines the observed state of ServiceTemplate
type ServiceTemplateStatus struct {
TemplateStatusMixin `json:",inline"`
}

func (t *ServiceTemplate) GetSpec() *TemplateSpecMixin {
return &t.Spec.TemplateSpecMixin
}

func (t *ServiceTemplate) GetStatus() *TemplateStatusMixin {
return &t.Status.TemplateStatusMixin
func init() {
SchemeBuilder.Register(&ServiceTemplate{}, &ServiceTemplateList{})
}
Loading

0 comments on commit a479f5e

Please sign in to comment.