Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconcile servicetemplates #10

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ test/e2e/*.log

# Vendoring directory
vendor

# mkdocs folder
mkdocs
7 changes: 7 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ resources:
kind: Management
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
domain: hmc.mirantis.com
group: hmc.mirantis.com
kind: Release
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
version: "3"
1 change: 1 addition & 0 deletions api/v1alpha1/clustertemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ClusterTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable"
Spec ClusterTemplateSpec `json:"spec,omitempty"`
Status ClusterTemplateStatus `json:"status,omitempty"`
}
Expand Down
49 changes: 48 additions & 1 deletion api/v1alpha1/managedcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const (
BlockingFinalizer = "hmc.mirantis.com/cleanup"
ManagedClusterFinalizer = "hmc.mirantis.com/managed-cluster"

FluxHelmChartNameKey = "helm.toolkit.fluxcd.io/name"
FluxHelmChartNameKey = "helm.toolkit.fluxcd.io/name"
FluxHelmChartNamespaceKey = "helm.toolkit.fluxcd.io/namespace"

HMCManagedLabelKey = "hmc.mirantis.com/managed"
HMCManagedLabelValue = "true"

Expand Down Expand Up @@ -60,6 +62,47 @@ const (
ProgressingReason string = "Progressing"
)

// //////////////////////////////////////////////////////////////////
// ManagedClusterServiceSpec represents a service within managed cluster
type ManagedClusterServiceSpec struct {
// Template is a reference to a Template object located in the same namespace.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
Template string `json:"template"`
// Install tells if this service should be installed.
// +kubebuilder:default:=true
Install bool `json:"install"`
// ReleaseName is the chart release.
// +kubebuilder:validation:MinLength=1
ReleaseName string `json:"releaseName"`
// ReleaseNamespace is the namespace the release will be installed in.
// It will default to ReleaseName if not provided.
// +optional
ReleaseNamespace string `json:"releaseNamespace"`
// CreateNamespace create the release namespace if not present.
// It will defaults to true if not provided.
// +kubebuilder:default:=true
// +optional
CreateNamespace bool `json:"createNamespace"`
// RegistryConfig to provide options to interact with registry.
// +optional
RegistryConfig *ManagedClusterServiceRegistryConfig `json:"registryConfig,omitempty"`
// Values is the helm values to be passed to the template.
// +optional
Values string `json:"values,omitempty"`
}

type ManagedClusterServiceRegistryConfig struct {
// PlainHTTP indicates to use insecure HTTP connections for the chart download
// +optional
PlainHTTP bool `json:"plainHTTP"`
// PlainHTTP indicates to use insecure HTTP connections for the chart download
// +optional
Insecure bool `json:"insecure"`
}

// //////////////////////////////////////////////////////////////////

// ManagedClusterSpec defines the desired state of ManagedCluster
type ManagedClusterSpec struct {
// DryRun specifies whether the template should be applied after validation or only validated.
Expand All @@ -74,6 +117,10 @@ type ManagedClusterSpec struct {
// the template and DryRun will be enabled.
// +optional
Config *apiextensionsv1.JSON `json:"config,omitempty"`
// Services is a list of services that could be installed on the
// target cluster created with the template.
// +optional
Services []ManagedClusterServiceSpec `json:"services,omitempty"`
}

// ManagedClusterStatus defines the observed state of ManagedCluster
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/providertemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ProviderTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable"
Spec ProviderTemplateSpec `json:"spec,omitempty"`
Status ProviderTemplateStatus `json:"status,omitempty"`
}
Expand Down
65 changes: 65 additions & 0 deletions api/v1alpha1/release_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ReleaseSpec defines the desired state of Release
type ReleaseSpec struct {
// Version of the HMC Release in the semver format.
Version string `json:"version"`
// UpgradeableVersions contains a list of versions available to upgrade from.
UpgradeableVersions []string `json:"upgradeableVersions,omitempty"`
// Providers contains a list of Providers associated with the Release.
Providers []Provider `json:"providers,omitempty"`
}

// ReleaseStatus defines the observed state of Release
type ReleaseStatus struct {
// Templates indicates the status of templates associated with the Release.
Templates ComponentStatus `json:"templates,omitempty"`
// Conditions contains details for the current state of the Release
Conditions []metav1.Condition `json:"conditions,omitempty"`
// Ready indicates whether HMC is ready to be upgraded to this Release.
Ready bool `json:"ready,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster

// Release is the Schema for the releases API
type Release struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ReleaseSpec `json:"spec,omitempty"`
Status ReleaseStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// ReleaseList contains a list of Release
type ReleaseList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Release `json:"items"`
}

func init() {
SchemeBuilder.Register(&Release{}, &ReleaseList{})
}
1 change: 1 addition & 0 deletions api/v1alpha1/servicetemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ServiceTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable"
Spec ServiceTemplateSpec `json:"spec,omitempty"`
Status ServiceTemplateStatus `json:"status,omitempty"`
}
Expand Down
11 changes: 7 additions & 4 deletions api/v1alpha1/templatemanagement_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,20 @@ type AccessRule struct {
ServiceTemplateChains []string `json:"serviceTemplateChains,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="((has(self.stringSelector) ? 1 : 0) + (has(self.selector) ? 1 : 0) + (has(self.list) ? 1 : 0)) <= 1", message="only one of spec.targetNamespaces.selector or spec.targetNamespaces.stringSelector spec.targetNamespaces.list can be specified"
// +kubebuilder:validation:XValidation:rule="((has(self.stringSelector) ? 1 : 0) + (has(self.selector) ? 1 : 0) + (has(self.list) ? 1 : 0)) <= 1", message="only one of spec.targetNamespaces.selector or spec.targetNamespaces.stringSelector or spec.targetNamespaces.list can be specified"

// TargetNamespaces defines the list of namespaces or the label selector to select namespaces
type TargetNamespaces struct {
// StringSelector is a label query to select namespaces.
// Mutually exclusive with Selector.
// Mutually exclusive with Selector and List.
// +optional
StringSelector string `json:"stringSelector,omitempty"`
// Selector is a structured label query to select namespaces.
// Mutually exclusive with StringSelector.
// Mutually exclusive with StringSelector and List.
// +optional
Selector metav1.LabelSelector `json:"selector,omitempty"`
Selector *metav1.LabelSelector `json:"selector,omitempty"`
// List is the list of namespaces to select.
// Mutually exclusive with StringSelector and Selector.
// +optional
List []string `json:"list,omitempty"`
}
Expand All @@ -88,6 +89,8 @@ type TemplateManagementStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// Current reflects the applied access rules configuration.
Current []AccessRule `json:"current,omitempty"`
// Error is the error message occurred during the reconciliation (if any)
Error string `json:"error,omitempty"`
}

func init() {
Expand Down
157 changes: 156 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

Loading
Loading