Skip to content

Commit

Permalink
Add new parameters to Management spec and status
Browse files Browse the repository at this point in the history
HMC-23
  • Loading branch information
eromanova committed Jun 14, 2024
1 parent d7ab7da commit 27f0c68
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 14 deletions.
62 changes: 58 additions & 4 deletions api/v1alpha1/management_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ limitations under the License.
package v1alpha1

import (
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/yaml"
)

const (
ManagementName = "hmc"
ManagementNamespace = "hmc-system"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand All @@ -28,14 +35,61 @@ type ManagementSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of Management. Edit management_types.go to remove/update
Foo string `json:"foo,omitempty"`
// Components is the list of supported management components
Components []Component `json:"components,omitempty"`
}

// Component represents HMC management component
type Component struct {
// 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
// values for the template.
// +optional
Config *apiextensionsv1.JSON `json:"config,omitempty"`
}

func (in *Component) HelmValues() (values map[string]interface{}, err error) {
if in.Config != nil {
err = yaml.Unmarshal(in.Config.Raw, &values)
}
return values, err
}

func (m ManagementSpec) SetDefaults() {
// TODO: Uncomment when Templates will be ready
/*
m.Components = []Component{
{
Template: "cluster-api",
},
{
Template: "k0smotron",
},
{
Template: "cluster-api-provider-aws",
},
}
*/
}

// ManagementStatus defines the observed state of Management
type ManagementStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
// ObservedGeneration is the last observed generation.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// Components contains the map with the status of Management components installation
Components map[string]ComponentStatus `json:"components,omitempty"`
}

// ComponentStatus is the status of Management component installation
type ComponentStatus struct {
// Success represents if a component installation was successful
Success bool `json:"success,omitempty"`
// Error stores as error message in case of failed installation
Error string `json:"error,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha1/template_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
)

const (
// TemplatesNamespace is the namespace where all management and provider Templates are located
TemplatesNamespace = "hmc-system"

// TemplateKind is the string representation of a Template.
TemplateKind = "Template"
// DeploymentKind is the string representation of a Deployment.
Expand Down
53 changes: 51 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

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

44 changes: 40 additions & 4 deletions charts/hmc/templates/management-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,49 @@ spec:
spec:
description: ManagementSpec defines the desired state of Management
properties:
foo:
description: Foo is an example field of Management. Edit management_types.go
to remove/update
type: string
components:
description: Components is the list of supported management components
items:
description: Component represents HMC management component
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
type: array
type: object
status:
description: ManagementStatus defines the observed state of Management
properties:
components:
additionalProperties:
description: ComponentStatus is the status of Management component
installation
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
description: Components contains the map with the status of Management
components installation
type: object
observedGeneration:
description: ObservedGeneration is the last observed generation.
format: int64
type: integer
type: object
type: object
served: true
Expand Down
45 changes: 41 additions & 4 deletions config/crd/bases/hmc.mirantis.com_managements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,50 @@ spec:
spec:
description: ManagementSpec defines the desired state of Management
properties:
foo:
description: Foo is an example field of Management. Edit management_types.go
to remove/update
type: string
components:
description: Components is the list of supported management components
items:
description: Component represents HMC management component
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
type: array
type: object
status:
description: ManagementStatus defines the observed state of Management
properties:
components:
additionalProperties:
description: ComponentStatus is the status of Management component
installation
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
description: Components contains the map with the status of Management
components installation
type: object
observedGeneration:
description: ObservedGeneration is the last observed generation.
format: int64
type: integer
type: object
type: object
served: true
Expand Down

0 comments on commit 27f0c68

Please sign in to comment.