Skip to content

Commit

Permalink
Merge pull request #27 from Mirantis/management-ctrl
Browse files Browse the repository at this point in the history
Management controller: API and main logic
  • Loading branch information
Kshatrix authored Jun 18, 2024
2 parents 8a2e4e8 + 6486ce3 commit 1058ca6
Show file tree
Hide file tree
Showing 29 changed files with 466 additions and 107 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ KIND_CLUSTER_NAME ?= hmc-dev
KIND_NETWORK ?= kind
LOCAL_REGISTRY_NAME ?= hmc-local-registry
LOCAL_REGISTRY_PORT ?= 5001
LOCAL_REGISTRY_REPO ?= oci://127.0.0.1:$(LOCAL_REGISTRY_PORT)/chart
LOCAL_REGISTRY_REPO ?= oci://127.0.0.1:$(LOCAL_REGISTRY_PORT)/charts

ifndef ignore-not-found
ignore-not-found = false
Expand Down
73 changes: 69 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,72 @@ 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"`
// Providers is the list of discovered supported providers
Providers ProvidersStatus `json:"providers,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"`
}

// 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
Expand Down
7 changes: 6 additions & 1 deletion api/v1alpha1/template_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import (
)

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

// ManagementKind is the string representation of a Management.
ManagementKind = "Management"
// TemplateKind is the string representation of a Template.
TemplateKind = "Template"
// DeploymentKind is the string representation of a Deployment.
Expand Down Expand Up @@ -90,7 +95,7 @@ type TemplateStatus struct {
// +optional
ChartRef *helmcontrollerv2.CrossNamespaceSourceReference `json:"chartRef,omitempty"`
// Type specifies the type of the provided template, as discovered from the Helm chart metadata.
// +kubebuilder:validation:Enum=deployment;provider;management
// +kubebuilder:validation:Enum=deployment;provider;core
Type string `json:"type,omitempty"`
// InfrastructureProviders specifies CAPI infrastructure providers associated with the template.
// +optional
Expand Down
84 changes: 82 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.

1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func main() {
if err = (&controller.ManagementReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Config: mgr.GetConfig(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Management")
os.Exit(1)
Expand Down
67 changes: 63 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,72 @@ 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
providers:
description: Providers is the list of discovered supported providers
properties:
bootstrap:
description: BootstrapProviders is the list of discovered bootstrap
providers
items:
type: string
type: array
controlPlane:
description: ControlPlaneProviders is the list of discovered control
plane providers
items:
type: string
type: array
infrastructure:
description: InfrastructureProviders is the list of discovered
infrastructure providers
items:
type: string
type: array
type: object
type: object
type: object
served: true
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/hmc.mirantis.com_templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ spec:
enum:
- deployment
- provider
- management
- core
type: string
valid:
description: Valid indicates whether the template passed validation
Expand Down
4 changes: 2 additions & 2 deletions config/rbac/awsprovider_editor_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
name: awsprovider-editor-role
rules:
- apiGroups:
- hmc.mirantis.com.hmc.mirantis.com
- hmc.mirantis.com
resources:
- awsproviders
verbs:
Expand All @@ -20,7 +20,7 @@ rules:
- update
- watch
- apiGroups:
- hmc.mirantis.com.hmc.mirantis.com
- hmc.mirantis.com
resources:
- awsproviders/status
verbs:
Expand Down
4 changes: 2 additions & 2 deletions config/rbac/awsprovider_viewer_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ metadata:
name: awsprovider-viewer-role
rules:
- apiGroups:
- hmc.mirantis.com.hmc.mirantis.com
- hmc.mirantis.com
resources:
- awsproviders
verbs:
- get
- list
- watch
- apiGroups:
- hmc.mirantis.com.hmc.mirantis.com
- hmc.mirantis.com
resources:
- awsproviders/status
verbs:
Expand Down
4 changes: 2 additions & 2 deletions config/rbac/deployment_editor_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
name: deployment-editor-role
rules:
- apiGroups:
- hmc.mirantis.com.hmc.mirantis.com
- hmc.mirantis.com
resources:
- deployments
verbs:
Expand All @@ -20,7 +20,7 @@ rules:
- update
- watch
- apiGroups:
- hmc.mirantis.com.hmc.mirantis.com
- hmc.mirantis.com
resources:
- deployments/status
verbs:
Expand Down
Loading

0 comments on commit 1058ca6

Please sign in to comment.