Skip to content

Commit

Permalink
Merge pull request #33 from Kshatrix/kubebuilder
Browse files Browse the repository at this point in the history
Template and Deployment CRD improvements
  • Loading branch information
Kshatrix authored Jun 18, 2024
2 parents 1058ca6 + f69e730 commit b215d9b
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 97 deletions.
27 changes: 27 additions & 0 deletions api/v1alpha1/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
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

// Providers is a structure holding different types of CAPI providers
type Providers struct {
// InfrastructureProviders is the list of CAPI infrastructure providers
InfrastructureProviders []string `json:"infrastructure,omitempty"`
// BootstrapProviders is the list of CAPI bootstrap providers
BootstrapProviders []string `json:"bootstrap,omitempty"`
// ControlPlaneProviders is the list of CAPI control plane providers
ControlPlaneProviders []string `json:"controlPlane,omitempty"`
}
4 changes: 4 additions & 0 deletions api/v1alpha1/deployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type DeploymentStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:resource:shortName=hmc-deploy;deploy
// +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="dryRun",type="string",JSONPath=".spec.dryRun",description="Dry Run",priority=1

// Deployment is the Schema for the deployments API
type Deployment struct {
Expand Down
13 changes: 2 additions & 11 deletions api/v1alpha1/management_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type ManagementStatus struct {
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// Providers is the list of discovered supported providers
Providers ProvidersStatus `json:"providers,omitempty"`
Providers Providers `json:"providers,omitempty"`
// Components contains the map with the status of Management components installation
Components map[string]ComponentStatus `json:"components,omitempty"`
}
Expand All @@ -93,18 +93,9 @@ type ComponentStatus struct {
Error string `json:"error,omitempty"`
}

// ProvidersStatus is the list of discovered supported providers
type ProvidersStatus struct {
// InfrastructureProviders is the list of discovered infrastructure providers
InfrastructureProviders []string `json:"infrastructure,omitempty"`
// BootstrapProviders is the list of discovered bootstrap providers
BootstrapProviders []string `json:"bootstrap,omitempty"`
// ControlPlaneProviders is the list of discovered control plane providers
ControlPlaneProviders []string `json:"controlPlane,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:resource:shortName=hmc-mgmt;mgmt

// Management is the Schema for the managements API
type Management struct {
Expand Down
16 changes: 7 additions & 9 deletions api/v1alpha1/template_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,8 @@ type TemplateStatus struct {
// Type specifies the type of the provided template, as discovered from the Helm chart metadata.
// +kubebuilder:validation:Enum=deployment;provider;core
Type string `json:"type,omitempty"`
// InfrastructureProviders specifies CAPI infrastructure providers associated with the template.
// +optional
InfrastructureProviders []string `json:"infrastructureProviders,omitempty"`
// BootstrapProviders specifies CAPI bootstrap providers associated with the template.
// +optional
BootstrapProviders []string `json:"bootstrapProviders,omitempty"`
// ControlPlaneProviders specifies CAPI control plane providers associated with the template.
// +optional
ControlPlaneProviders []string `json:"controlPlaneProviders,omitempty"`
// Providers represent required/exposed CAPI providers depending on the template type.
Providers Providers `json:"providers,omitempty"`
// ObservedGeneration is the last observed generation.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Expand All @@ -121,6 +114,11 @@ type TemplateValidationStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:resource:shortName=hmc-tmpl;tmpl
// +kubebuilder:printcolumn:name="type",type="string",JSONPath=".status.type",description="Type",priority=0
// +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

// Template is the Schema for the templates API
type Template struct {
Expand Down
24 changes: 5 additions & 19 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion config/crd/bases/hmc.mirantis.com_deployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,28 @@ spec:
kind: Deployment
listKind: DeploymentList
plural: deployments
shortNames:
- hmc-deploy
- deploy
singular: deployment
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- description: Valid
jsonPath: .status.valid
name: valid
type: boolean
- description: Validation Error
jsonPath: .status.validationError
name: validationError
priority: 1
type: string
- description: Dry Run
jsonPath: .spec.dryRun
name: dryRun
priority: 1
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: Deployment is the Schema for the deployments API
Expand Down
11 changes: 7 additions & 4 deletions config/crd/bases/hmc.mirantis.com_managements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ spec:
kind: Management
listKind: ManagementList
plural: managements
shortNames:
- hmc-mgmt
- mgmt
singular: management
scope: Namespaced
versions:
Expand Down Expand Up @@ -87,20 +90,20 @@ spec:
description: Providers is the list of discovered supported providers
properties:
bootstrap:
description: BootstrapProviders is the list of discovered bootstrap
description: BootstrapProviders is the list of CAPI bootstrap
providers
items:
type: string
type: array
controlPlane:
description: ControlPlaneProviders is the list of discovered control
description: ControlPlaneProviders is the list of CAPI control
plane providers
items:
type: string
type: array
infrastructure:
description: InfrastructureProviders is the list of discovered
infrastructure providers
description: InfrastructureProviders is the list of CAPI infrastructure
providers
items:
type: string
type: array
Expand Down
65 changes: 46 additions & 19 deletions config/crd/bases/hmc.mirantis.com_templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,32 @@ spec:
kind: Template
listKind: TemplateList
plural: templates
shortNames:
- hmc-tmpl
- tmpl
singular: template
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- description: Type
jsonPath: .status.type
name: type
type: string
- description: Valid
jsonPath: .status.valid
name: valid
type: boolean
- description: Validation Error
jsonPath: .status.validationError
name: validationError
priority: 1
type: string
- description: Description
jsonPath: .status.description
name: description
priority: 1
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: Template is the Schema for the templates API
Expand Down Expand Up @@ -92,12 +114,6 @@ spec:
status:
description: TemplateStatus defines the observed state of Template
properties:
bootstrapProviders:
description: BootstrapProviders specifies CAPI bootstrap providers
associated with the template.
items:
type: string
type: array
chartRef:
description: |-
ChartRef is a reference to a source controller resource containing the
Expand Down Expand Up @@ -133,25 +149,36 @@ spec:
Config demonstrates available parameters for template customization,
that can be used when creating Deployment objects.
x-kubernetes-preserve-unknown-fields: true
controlPlaneProviders:
description: ControlPlaneProviders specifies CAPI control plane providers
associated with the template.
items:
type: string
type: array
description:
description: Description contains information about the template.
type: string
infrastructureProviders:
description: InfrastructureProviders specifies CAPI infrastructure
providers associated with the template.
items:
type: string
type: array
observedGeneration:
description: ObservedGeneration is the last observed generation.
format: int64
type: integer
providers:
description: Providers represent required/exposed CAPI providers depending
on the template type.
properties:
bootstrap:
description: BootstrapProviders is the list of CAPI bootstrap
providers
items:
type: string
type: array
controlPlane:
description: ControlPlaneProviders is the list of CAPI control
plane providers
items:
type: string
type: array
infrastructure:
description: InfrastructureProviders is the list of CAPI infrastructure
providers
items:
type: string
type: array
type: object
type:
description: Type specifies the type of the provided template, as
discovered from the Helm chart metadata.
Expand Down
2 changes: 1 addition & 1 deletion config/samples/hmc.mirantis.com_v1alpha1_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ metadata:
app.kubernetes.io/managed-by: kustomize
name: deployment-sample
spec:
# TODO(user): Add fields here
template: aws-standalone-cp
10 changes: 5 additions & 5 deletions internal/controller/management_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r *ManagementReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

var errs error
detectedProviders := hmc.ProvidersStatus{}
detectedProviders := hmc.Providers{}
detectedComponents := make(map[string]hmc.ComponentStatus)

for _, component := range management.Spec.Components {
Expand Down Expand Up @@ -119,7 +119,7 @@ func (r *ManagementReconciler) Reconcile(ctx context.Context, req ctrl.Request)

func updateComponentsStatus(
components map[string]hmc.ComponentStatus,
providers *hmc.ProvidersStatus,
providers *hmc.Providers,
componentName string,
templateStatus hmc.TemplateStatus,
err string) {
Expand All @@ -130,9 +130,9 @@ func updateComponentsStatus(
}

if err == "" {
providers.InfrastructureProviders = append(providers.InfrastructureProviders, templateStatus.InfrastructureProviders...)
providers.BootstrapProviders = append(providers.BootstrapProviders, templateStatus.BootstrapProviders...)
providers.ControlPlaneProviders = append(providers.ControlPlaneProviders, templateStatus.ControlPlaneProviders...)
providers.InfrastructureProviders = append(providers.InfrastructureProviders, templateStatus.Providers.InfrastructureProviders...)
providers.BootstrapProviders = append(providers.BootstrapProviders, templateStatus.Providers.BootstrapProviders...)
providers.ControlPlaneProviders = append(providers.ControlPlaneProviders, templateStatus.Providers.ControlPlaneProviders...)
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/controller/template_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ func (r *TemplateReconciler) parseChartMetadata(template *hmc.Template, chart *c

template.Status.Type = templateType
if infraProviders != "" {
template.Status.InfrastructureProviders = strings.Split(infraProviders, ",")
template.Status.Providers.InfrastructureProviders = strings.Split(infraProviders, ",")
}
if bootstrapProviders != "" {
template.Status.BootstrapProviders = strings.Split(bootstrapProviders, ",")
template.Status.Providers.BootstrapProviders = strings.Split(bootstrapProviders, ",")
}
if cpProviders != "" {
template.Status.ControlPlaneProviders = strings.Split(cpProviders, ",")
template.Status.Providers.ControlPlaneProviders = strings.Split(cpProviders, ",")
}
return nil
}
Expand Down
20 changes: 19 additions & 1 deletion templates/hmc/templates/deployment-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,28 @@ spec:
kind: Deployment
listKind: DeploymentList
plural: deployments
shortNames:
- hmc-deploy
- deploy
singular: deployment
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- description: Valid
jsonPath: .status.valid
name: valid
type: boolean
- description: Validation Error
jsonPath: .status.validationError
name: validationError
priority: 1
type: string
- description: Dry Run
jsonPath: .spec.dryRun
name: dryRun
priority: 1
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: Deployment is the Schema for the deployments API
Expand Down
Loading

0 comments on commit b215d9b

Please sign in to comment.