Skip to content

Commit

Permalink
Merge pull request #43 from Kshatrix/separate-core
Browse files Browse the repository at this point in the history
Separate Core components
  • Loading branch information
Kshatrix authored Jun 20, 2024
2 parents 34b81fd + 38ddf68 commit f2d85ee
Show file tree
Hide file tree
Showing 9 changed files with 374 additions and 55 deletions.
47 changes: 36 additions & 11 deletions api/v1alpha1/management_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,35 @@ import (
"k8s.io/apimachinery/pkg/util/yaml"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
const (
DefaultCoreHMCTemplate = "hmc"
DefaultCoreCAPITemplate = "cluster-api"
DefaultCoreCertManagerTemplate = "cert-manager"
)

// ManagementSpec defines the desired state of Management
type ManagementSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Core holds the core Management components that are mandatory.
// If not specified, will be populated with the default values.
Core *Core `json:"core,omitempty"`

// Providers is the list of supported CAPI providers.
Providers []Component `json:"providers,omitempty"`
}

// Components is the list of supported management components
Components []Component `json:"components,omitempty"`
// Core represents a structure describing core Management components.
type Core struct {
// HMC represents the core HMC component and references the HMC template.
HMC Component `json:"hmc"`
// CAPI represents the core Cluster API component and references the Cluster API template.
CAPI Component `json:"capi"`
// CertManager represents the Cert Manager component and references the Cert Manager template.
CertManager Component `json:"certManager"`
}

// Component represents HMC management component
type Component struct {
// Template is the name of the Template associated with this component
// Template is the name of the Template associated with this component.
Template string `json:"template"`
// Config allows to provide parameters for management component customization.
// If no Config provided, the field will be populated with the default
Expand All @@ -55,7 +69,7 @@ func (in *Component) HelmValues() (values map[string]interface{}, err error) {
func (m ManagementSpec) SetDefaults() {
// TODO: Uncomment when Templates will be ready
/*
m.Components = []Component{
m.Providers = []Component{
{
Template: "cluster-api",
},
Expand All @@ -74,10 +88,12 @@ type ManagementStatus struct {
// ObservedGeneration is the last observed generation.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// AvailableProviders is the list of discovered supported providers
// AvailableProviders holds all CAPI providers available on the Management cluster.
AvailableProviders Providers `json:"availableProviders,omitempty"`
// Components contains the map with the status of Management components installation
Components map[string]ComponentStatus `json:"components,omitempty"`
// Core indicates the status of installed core components.
Core CoreStatus `json:"core,omitempty"`
// Providers indicates the status of installed CAPI providers.
Providers map[string]ComponentStatus `json:"providers,omitempty"`
}

// ComponentStatus is the status of Management component installation
Expand All @@ -88,6 +104,15 @@ type ComponentStatus struct {
Error string `json:"error,omitempty"`
}

type CoreStatus struct {
// HMC indicates the status of the installed HMC component.
HMC ComponentStatus `json:"HMC,omitempty"`
// CAPI indicates the status of the installed CAPI component.
CAPI ComponentStatus `json:"CAPI,omitempty"`
// CertManager indicates the status of the installed CertManager component.
CertManager ComponentStatus `json:"certManager,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:resource:shortName=hmc-mgmt;mgmt
Expand Down
50 changes: 46 additions & 4 deletions api/v1alpha1/zz_generated.deepcopy.go

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

125 changes: 113 additions & 12 deletions config/crd/bases/hmc.mirantis.com_managements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,69 @@ spec:
spec:
description: ManagementSpec defines the desired state of Management
properties:
components:
description: Components is the list of supported management components
core:
description: |-
Core holds the core Management components that are mandatory.
If not specified, will be populated with the default values.
properties:
capi:
description: CAPI represents the core Cluster API component and
references the Cluster API template.
properties:
config:
description: |-
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.
x-kubernetes-preserve-unknown-fields: true
template:
description: Template is the name of the Template associated
with this component.
type: string
required:
- template
type: object
certManager:
description: CertManager represents the Cert Manager component
and references the Cert Manager template.
properties:
config:
description: |-
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.
x-kubernetes-preserve-unknown-fields: true
template:
description: Template is the name of the Template associated
with this component.
type: string
required:
- template
type: object
hmc:
description: HMC represents the core HMC component and references
the HMC template.
properties:
config:
description: |-
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.
x-kubernetes-preserve-unknown-fields: true
template:
description: Template is the name of the Template associated
with this component.
type: string
required:
- template
type: object
required:
- capi
- certManager
- hmc
type: object
providers:
description: Providers is the list of supported CAPI providers.
items:
description: Component represents HMC management component
properties:
Expand All @@ -55,7 +116,7 @@ spec:
x-kubernetes-preserve-unknown-fields: true
template:
description: Template is the name of the Template associated
with this component
with this component.
type: string
required:
- template
Expand All @@ -66,8 +127,8 @@ spec:
description: ManagementStatus defines the observed state of Management
properties:
availableProviders:
description: AvailableProviders is the list of discovered supported
providers
description: AvailableProviders holds all CAPI providers available
on the Management cluster.
properties:
bootstrap:
description: BootstrapProviders is the list of CAPI bootstrap
Expand All @@ -88,7 +149,52 @@ spec:
type: string
type: array
type: object
components:
core:
description: Core indicates the status of installed core components.
properties:
CAPI:
description: CAPI indicates the status of the installed CAPI component.
properties:
error:
description: Error stores as error message in case of failed
installation
type: string
success:
description: Success represents if a component installation
was successful
type: boolean
type: object
HMC:
description: HMC indicates the status of the installed HMC component.
properties:
error:
description: Error stores as error message in case of failed
installation
type: string
success:
description: Success represents if a component installation
was successful
type: boolean
type: object
certManager:
description: CertManager indicates the status of the installed
CertManager component.
properties:
error:
description: Error stores as error message in case of failed
installation
type: string
success:
description: Success represents if a component installation
was successful
type: boolean
type: object
type: object
observedGeneration:
description: ObservedGeneration is the last observed generation.
format: int64
type: integer
providers:
additionalProperties:
description: ComponentStatus is the status of Management component
installation
Expand All @@ -102,13 +208,8 @@ spec:
was successful
type: boolean
type: object
description: Components contains the map with the status of Management
components installation
description: Providers indicates the status of installed CAPI providers.
type: object
observedGeneration:
description: ObservedGeneration is the last observed generation.
format: int64
type: integer
type: object
type: object
served: true
Expand Down
3 changes: 1 addition & 2 deletions config/dev/management.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ metadata:
name: hmc
namespace: hmc-system
spec:
components:
- template: cluster-api
providers:
- template: cluster-api-provider-aws
config:
credentialsSecretName: aws-credentials
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22.0

require (
github.com/fluxcd/helm-controller/api v1.0.1
github.com/fluxcd/pkg/apis/meta v1.5.0
github.com/fluxcd/source-controller/api v1.3.0
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/onsi/ginkgo/v2 v2.19.0
Expand Down Expand Up @@ -50,7 +51,6 @@ require (
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fluxcd/pkg/apis/acl v0.3.0 // indirect
github.com/fluxcd/pkg/apis/kustomize v1.5.0 // indirect
github.com/fluxcd/pkg/apis/meta v1.5.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (r *DeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

// TODO: this should be implemented in admission controller instead
if changed := applyDefaultConfiguration(deployment, template); changed {
if changed := applyDefaultDeploymentConfiguration(deployment, template); changed {
l.Info("Applying default configuration")
return ctrl.Result{}, r.Client.Update(ctx, deployment)
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func (r *DeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request)
UID: deployment.UID,
}
_, err := helm.ReconcileHelmRelease(ctx, r.Client, deployment.Name, deployment.Namespace, deployment.Spec.Config,
ownerRef, template.Status.ChartRef, defaultReconcileInterval)
ownerRef, template.Status.ChartRef, defaultReconcileInterval, nil)
if err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func (r *DeploymentReconciler) getSource(ctx context.Context, ref *hcv2.CrossNam
return &hc, nil
}

func applyDefaultConfiguration(deployment *hmc.Deployment, template *hmc.Template) (changed bool) {
func applyDefaultDeploymentConfiguration(deployment *hmc.Deployment, template *hmc.Template) (changed bool) {
if deployment.Spec.Config != nil || template.Status.Config == nil {
// Only apply defaults when there's no configuration provided
return false
Expand Down
Loading

0 comments on commit f2d85ee

Please sign in to comment.