Skip to content

Commit

Permalink
Add hmc templates controller
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Pavlov <[email protected]>
  • Loading branch information
Kshatrix committed Jun 4, 2024
1 parent 8adab97 commit d7b6fe5
Show file tree
Hide file tree
Showing 24 changed files with 648 additions and 201 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.21 AS builder
FROM golang:1.22 AS builder
ARG TARGETOS
ARG TARGETARCH

Expand All @@ -14,7 +14,7 @@ RUN go mod download
# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/
COPY internal/ internal/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ import (
// DeploymentSpec defines the desired state of Deployment
type DeploymentSpec struct {
// DryRun specifies whether the template should be applied after validation or only validated.
// +kubebuilder:validation:Optional
DryRun bool `json:"dryRun"`
// +optional
DryRun bool `json:"dryRun,omitempty"`
// Template is a reference to a Template object located in the same namespace.
// +kubebuilder:validation:Required
Template string `json:"template"`
// Configuration allows to provide parameters for template customization.
// If no Configuration provided, the field will be populated with the default values for
// the template and DryRun will be enabled.
// +kubebuilder:validation:Optional
Configuration apiextensionsv1.JSON `json:"configuration"`
// +optional
Configuration apiextensionsv1.JSON `json:"configuration,omitempty"`
}

// DeploymentStatus defines the observed state of Deployment
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ limitations under the License.
package v1alpha1

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

helmcontrollerv2 "github.com/fluxcd/helm-controller/api/v2"
)

// TemplateSpec defines the desired state of Template
Expand All @@ -26,25 +29,45 @@ type TemplateSpec struct {
// +kubebuilder:validation:Enum=aws
// +kubebuilder:validation:Required
Provider string `json:"provider"`
// HelmChartURL is a URL of the helm chart representing the template.
// Helm holds a reference to a Helm chart representing the HMC template
// +kubebuilder:validation:Required
HelmChartURL string `json:"helmChartURL"`
Helm HelmSpec `json:"helm"`
}

// +kubebuilder:validation:XValidation:rule="(has(self.chartName) && !has(self.chartRef)) || (!has(self.chartName) && has(self.chartRef))", message="either chartName or chartRef must be set"

// HelmSpec references a Helm chart representing the HMC template
type HelmSpec struct {
// ChartName is a name of a Helm chart representing the template in the HMC repository.
// +optional
ChartName string `json:"chartName,omitempty"`
// ChartVersion is a version of a Helm chart representing the template in the HMC repository.
// +optional
ChartVersion string `json:"chartVersion,omitempty"`
// ChartRef is a reference to a source controller resource containing the
// Helm chart representing the template.
// +optional
ChartRef *helmcontrollerv2.CrossNamespaceSourceReference `json:"chartRef,omitempty"`
}

// TemplateStatus defines the observed state of Template
type TemplateStatus struct {
TemplateValidationStatus `json:",inline"`
// Descriptions contains information about the template.
// +optional
Description string `json:"description"`
Description string `json:"description,omitempty"`
// Configuration demonstrates available parameters for template customization,
// that can be used when creating Deployment objects.
// +optional
Configuration apiextensionsv1.JSON `json:"configuration,omitempty"`
}

type TemplateValidationStatus struct {
// Valid indicates whether the template passed validation or not.
Valid bool `json:"valid"`
// ValidationError provides information regarding issues encountered during template validation.
// +optional
ValidationError string `json:"validationError"`
ValidationError string `json:"validationError,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
27 changes: 25 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.

13 changes: 13 additions & 0 deletions charts/hmc/templates/manager-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ rules:
- get
- patch
- update
- apiGroups:
- source.toolkit.fluxcd.io
resources:
- helmcharts
- helmrepositories
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
58 changes: 53 additions & 5 deletions charts/hmc/templates/template-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,71 @@ spec:
spec:
description: TemplateSpec defines the desired state of Template
properties:
helmChartURL:
description: HelmChartURL is a URL of the helm chart representing the
template.
type: string
helm:
description: Helm holds a reference to a Helm chart representing the
HMC template
properties:
chartName:
description: ChartName is a name of a Helm chart representing the
template in the HMC repository.
type: string
chartRef:
description: |-
ChartRef is a reference to a source controller resource containing the
Helm chart representing the template.
properties:
apiVersion:
description: APIVersion of the referent.
type: string
kind:
description: Kind of the referent.
enum:
- OCIRepository
- HelmChart
type: string
name:
description: Name of the referent.
maxLength: 253
minLength: 1
type: string
namespace:
description: |-
Namespace of the referent, defaults to the namespace of the Kubernetes
resource object that contains the reference.
maxLength: 63
minLength: 1
type: string
required:
- kind
- name
type: object
chartVersion:
description: ChartVersion is a version of a Helm chart representing
the template in the HMC repository.
type: string
type: object
x-kubernetes-validations:
- message: either chartName or chartRef must be set
rule: (has(self.chartName) && !has(self.chartRef)) || (!has(self.chartName)
&& has(self.chartRef))
provider:
description: Provider specifies a CAPI provider associated with the
template.
enum:
- aws
type: string
required:
- helmChartURL
- helm
- provider
type: object
status:
description: TemplateStatus defines the observed state of Template
properties:
configuration:
description: |-
Configuration demonstrates available parameters for template customization,
that can be used when creating Deployment objects.
x-kubernetes-preserve-unknown-fields: true
description:
description: Descriptions contains information about the template.
type: string
Expand Down
4 changes: 4 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

hcv2 "github.com/fluxcd/helm-controller/api/v2"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand All @@ -48,6 +50,8 @@ func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(hmcmirantiscomv1alpha1.AddToScheme(scheme))
utilruntime.Must(sourcev1.AddToScheme(scheme))
utilruntime.Must(hcv2.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

Expand Down
58 changes: 53 additions & 5 deletions config/crd/bases/hmc.mirantis.com_templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,71 @@ spec:
spec:
description: TemplateSpec defines the desired state of Template
properties:
helmChartURL:
description: HelmChartURL is a URL of the helm chart representing
the template.
type: string
helm:
description: Helm holds a reference to a Helm chart representing the
HMC template
properties:
chartName:
description: ChartName is a name of a Helm chart representing
the template in the HMC repository.
type: string
chartRef:
description: |-
ChartRef is a reference to a source controller resource containing the
Helm chart representing the template.
properties:
apiVersion:
description: APIVersion of the referent.
type: string
kind:
description: Kind of the referent.
enum:
- OCIRepository
- HelmChart
type: string
name:
description: Name of the referent.
maxLength: 253
minLength: 1
type: string
namespace:
description: |-
Namespace of the referent, defaults to the namespace of the Kubernetes
resource object that contains the reference.
maxLength: 63
minLength: 1
type: string
required:
- kind
- name
type: object
chartVersion:
description: ChartVersion is a version of a Helm chart representing
the template in the HMC repository.
type: string
type: object
x-kubernetes-validations:
- message: either chartName or chartRef must be set
rule: (has(self.chartName) && !has(self.chartRef)) || (!has(self.chartName)
&& has(self.chartRef))
provider:
description: Provider specifies a CAPI provider associated with the
template.
enum:
- aws
type: string
required:
- helmChartURL
- helm
- provider
type: object
status:
description: TemplateStatus defines the observed state of Template
properties:
configuration:
description: |-
Configuration demonstrates available parameters for template customization,
that can be used when creating Deployment objects.
x-kubernetes-preserve-unknown-fields: true
description:
description: Descriptions contains information about the template.
type: string
Expand Down
13 changes: 13 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,16 @@ rules:
- get
- patch
- update
- apiGroups:
- source.toolkit.fluxcd.io
resources:
- helmcharts
- helmrepositories
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
Loading

0 comments on commit d7b6fe5

Please sign in to comment.