Skip to content

Commit

Permalink
Expose additional sveltos settings
Browse files Browse the repository at this point in the history
  • Loading branch information
wahabmk committed Dec 20, 2024
1 parent cbd3fe3 commit c7234f2
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 65 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ templates-generate:
@hack/templates.sh

.PHONY: generate-all
generate-all: generate manifests templates-generate add-license
generate-all: generate manifests templates-generate #add-license

.PHONY: fmt
fmt: ## Run go fmt against code.
Expand Down Expand Up @@ -153,7 +153,7 @@ collect-airgap-providers: yq helm clusterctl $(PROVIDER_TEMPLATES_DIR) $(LOCALBI
$(SHELL) hack/collect-airgap-providers.sh

.PHONY: helm-package
helm-package: $(CHARTS_PACKAGE_DIR) $(EXTENSION_CHARTS_PACKAGE_DIR) helm collect-airgap-providers
helm-package: $(CHARTS_PACKAGE_DIR) $(EXTENSION_CHARTS_PACKAGE_DIR) helm # collect-airgap-providers
@make $(patsubst %,package-%-tmpl,$(TEMPLATE_FOLDERS))

bundle-images: dev-apply $(IMAGES_PACKAGE_DIR) ## Create a tarball with all images used by HMC.
Expand Down
24 changes: 2 additions & 22 deletions api/v1alpha1/managedcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,9 @@ type ManagedClusterSpec struct {
Template string `json:"template"`
// Name reference to the related Credentials object.
Credential string `json:"credential,omitempty"`
// Services is a list of services created via ServiceTemplates
// that could be installed on the target cluster.
Services []ServiceSpec `json:"services,omitempty"`

// +kubebuilder:default:=100
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=2147483646

// ServicesPriority sets the priority for the services defined in this spec.
// Higher value means higher priority and lower means lower.
// In case of conflict with another object managing the service,
// the one with higher priority will get to deploy its services.
ServicesPriority int32 `json:"servicesPriority,omitempty"`
// DryRun specifies whether the template should be applied after validation or only validated.
DryRun bool `json:"dryRun,omitempty"`

// +kubebuilder:default:=false

// StopOnConflict specifies what to do in case of a conflict.
// E.g. If another object is already managing a service.
// By default the remaining services will be deployed even if conflict is detected.
// If set to true, the deployment will stop after encountering the first conflict.
StopOnConflict bool `json:"stopOnConflict,omitempty"`
DryRun bool `json:"dryRun,omitempty"`
ServicesSpec `json:",inline"`
}

// ManagedClusterStatus defines the observed state of ManagedCluster
Expand Down
19 changes: 15 additions & 4 deletions api/v1alpha1/multiclusterservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package v1alpha1

import (
sveltosv1beta1 "github.com/projectsveltos/addon-controller/api/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -43,6 +44,8 @@ type ServiceSpec struct {
// The string type is used in order to allow for templating.
Values string `json:"values,omitempty"`

ValuesFrom []sveltosv1beta1.ValueFrom `json:"valuesFrom,omitempty"`

// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253

Expand All @@ -61,10 +64,7 @@ type ServiceSpec struct {
Disable bool `json:"disable,omitempty"`
}

// MultiClusterServiceSpec defines the desired state of MultiClusterService
type MultiClusterServiceSpec struct {
// ClusterSelector identifies target clusters to manage services on.
ClusterSelector metav1.LabelSelector `json:"clusterSelector,omitempty"`
type ServicesSpec struct {
// Services is a list of services created via ServiceTemplates
// that could be installed on the target cluster.
Services []ServiceSpec `json:"services,omitempty"`
Expand All @@ -86,6 +86,17 @@ type MultiClusterServiceSpec struct {
// By default the remaining services will be deployed even if conflict is detected.
// If set to true, the deployment will stop after encountering the first conflict.
StopOnConflict bool `json:"stopOnConflict,omitempty"`

Reload bool `json:"reload,omitempty"`
TemplateResourceRefs []sveltosv1beta1.TemplateResourceRef `json:"templateResourceRefs,omitempty"`
PolicyRefs []sveltosv1beta1.PolicyRef `json:"policyRefs,omitempty"`
}

// MultiClusterServiceSpec defines the desired state of MultiClusterService
type MultiClusterServiceSpec struct {
// ClusterSelector identifies target clusters to manage services on.
ClusterSelector metav1.LabelSelector `json:"clusterSelector,omitempty"`
ServicesSpec `json:",inline"`
}

// ServiceStatus contains details for the state of services.
Expand Down
50 changes: 40 additions & 10 deletions api/v1alpha1/zz_generated.deepcopy.go

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

9 changes: 6 additions & 3 deletions internal/controller/managedcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,12 @@ func (r *ManagedClusterReconciler) updateServices(ctx context.Context, mc *hmc.M
hmc.FluxHelmChartNameKey: mc.Name,
},
},
HelmChartOpts: opts,
Priority: mc.Spec.ServicesPriority,
StopOnConflict: mc.Spec.StopOnConflict,
HelmChartOpts: opts,
Priority: mc.Spec.ServicesPriority,
StopOnConflict: mc.Spec.StopOnConflict,
Reload: mc.Spec.Reload,
TemplateResourceRefs: mc.Spec.TemplateResourceRefs,
PolicyRefs: mc.Spec.PolicyRefs,
}); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to reconcile Profile: %w", err)
}
Expand Down
10 changes: 6 additions & 4 deletions internal/controller/managedcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ var _ = Describe("ManagedCluster Controller", func() {
Spec: hmc.ManagedClusterSpec{
Template: templateName,
Credential: credentialName,
Services: []hmc.ServiceSpec{
{
Template: svcTemplateName,
Name: "test-svc-name",
ServicesSpec: hmc.ServicesSpec{
Services: []hmc.ServiceSpec{
{
Template: svcTemplateName,
Name: "test-svc-name",
},
},
},
},
Expand Down
11 changes: 7 additions & 4 deletions internal/controller/multiclusterservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ func (r *MultiClusterServiceReconciler) reconcileUpdate(ctx context.Context, mcs
Name: mcs.Name,
UID: mcs.UID,
},
LabelSelector: mcs.Spec.ClusterSelector,
HelmChartOpts: opts,
Priority: mcs.Spec.ServicesPriority,
StopOnConflict: mcs.Spec.StopOnConflict,
LabelSelector: mcs.Spec.ClusterSelector,
HelmChartOpts: opts,
Priority: mcs.Spec.ServicesPriority,
StopOnConflict: mcs.Spec.StopOnConflict,
Reload: mcs.Spec.Reload,
TemplateResourceRefs: mcs.Spec.TemplateResourceRefs,
PolicyRefs: mcs.Spec.PolicyRefs,
}); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to reconcile ClusterProfile: %w", err)
}
Expand Down
18 changes: 10 additions & 8 deletions internal/controller/multiclusterservice_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,16 @@ var _ = Describe("MultiClusterService Controller", func() {
},
},
Spec: hmc.MultiClusterServiceSpec{
Services: []hmc.ServiceSpec{
{
Template: serviceTemplate1Name,
Name: helmChartReleaseName,
},
{
Template: serviceTemplate2Name,
Name: helmChartReleaseName,
ServicesSpec: hmc.ServicesSpec{
Services: []hmc.ServiceSpec{
{
Template: serviceTemplate1Name,
Name: helmChartReleaseName,
},
{
Template: serviceTemplate2Name,
Name: helmChartReleaseName,
},
},
},
},
Expand Down
26 changes: 18 additions & 8 deletions internal/sveltos/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ import (
)

type ReconcileProfileOpts struct {

Check failure on line 35 in internal/sveltos/profile.go

View workflow job for this annotation

GitHub Actions / Build and Unit Test

fieldalignment: struct with 104 pointer bytes could be 96 (govet)
OwnerReference *metav1.OwnerReference
LabelSelector metav1.LabelSelector
HelmChartOpts []HelmChartOpts
Priority int32
StopOnConflict bool
OwnerReference *metav1.OwnerReference
LabelSelector metav1.LabelSelector
HelmChartOpts []HelmChartOpts
Priority int32
StopOnConflict bool
Reload bool
TemplateResourceRefs []sveltosv1beta1.TemplateResourceRef
PolicyRefs []sveltosv1beta1.PolicyRef
}

type HelmChartOpts struct {

Check failure on line 46 in internal/sveltos/profile.go

View workflow job for this annotation

GitHub Actions / Build and Unit Test

fieldalignment: struct with 136 pointer bytes could be 128 (govet)
CredentialsSecretRef *corev1.SecretReference
Values string
ValuesFrom []sveltosv1beta1.ValueFrom
RepositoryURL string
RepositoryName string
ChartName string
Expand Down Expand Up @@ -178,6 +182,7 @@ func GetHelmChartOpts(ctx context.Context, c client.Client, namespace string, se
chartName := chart.Spec.Chart
opt := HelmChartOpts{
Values: svc.Values,
ValuesFrom: svc.ValuesFrom,
RepositoryURL: repo.Spec.URL,
// We don't have repository name so chart name becomes repository name.
RepositoryName: chartName,
Expand Down Expand Up @@ -230,9 +235,12 @@ func GetSpec(opts *ReconcileProfileOpts) (*sveltosv1beta1.Spec, error) {
ClusterSelector: libsveltosv1beta1.Selector{
LabelSelector: opts.LabelSelector,
},
Tier: tier,
ContinueOnConflict: !opts.StopOnConflict,
HelmCharts: make([]sveltosv1beta1.HelmChart, 0, len(opts.HelmChartOpts)),
Tier: tier,
ContinueOnConflict: !opts.StopOnConflict,
HelmCharts: make([]sveltosv1beta1.HelmChart, 0, len(opts.HelmChartOpts)),
Reloader: opts.Reload,
TemplateResourceRefs: opts.TemplateResourceRefs,
PolicyRefs: opts.PolicyRefs,
}

for _, hc := range opts.HelmChartOpts {
Expand All @@ -259,6 +267,8 @@ func GetSpec(opts *ReconcileProfileOpts) (*sveltosv1beta1.Spec, error) {
}

helmChart.Values = hc.Values
helmChart.ValuesFrom = hc.ValuesFrom

spec.HelmCharts = append(spec.HelmCharts, helmChart)
}

Expand Down
Loading

0 comments on commit c7234f2

Please sign in to comment.