Skip to content

Commit

Permalink
Reconcile (Cluster)Profile 'spec.templateResourceRefs' and 'spec.po…
Browse files Browse the repository at this point in the history
…licyRef' field
  • Loading branch information
s3rj1k committed Jan 16, 2025
1 parent 9bca0cf commit 2bec5ed
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
59 changes: 54 additions & 5 deletions internal/controller/clusterdeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,43 @@ func (r *ClusterDeploymentReconciler) aggregateCapoConditions(ctx context.Contex
return requeue, errs
}

func getProjectTemplateResourceRefs(cred *kcm.Credential) []sveltosv1beta1.TemplateResourceRef {
if cred.Spec.IdentityRef == nil {
return nil
}

return []sveltosv1beta1.TemplateResourceRef{
{
Resource: *cred.Spec.IdentityRef,
Identifier: "InfrastructureProviderIdentity",
},
{
Resource: corev1.ObjectReference{
APIVersion: "v1",
Kind: "Secret",
Namespace: cred.Spec.IdentityRef.Namespace,
Name: cred.Spec.IdentityRef.Name + "-secret",
},
Identifier: "InfrastructureProviderIdentitySecret",
},
}
}

func getProjectPolicyRefs(cred *kcm.Credential) []sveltosv1beta1.PolicyRef {
if cred.Spec.IdentityRef == nil {
return nil
}

return []sveltosv1beta1.PolicyRef{
{
Kind: "ConfigMap",
Namespace: cred.Spec.IdentityRef.Namespace,
Name: cred.Spec.IdentityRef.Name + "-resource-template",
DeploymentType: sveltosv1beta1.DeploymentTypeRemote,
},
}
}

// updateServices reconciles services provided in ClusterDeployment.Spec.Services.
func (r *ClusterDeploymentReconciler) updateServices(ctx context.Context, mc *kcm.ClusterDeployment) (_ ctrl.Result, err error) {
l := ctrl.LoggerFrom(ctx)
Expand Down Expand Up @@ -460,6 +497,15 @@ func (r *ClusterDeploymentReconciler) updateServices(ctx context.Context, mc *kc
return ctrl.Result{}, err
}

cred := &kcm.Credential{}
err = r.Client.Get(ctx, client.ObjectKey{
Name: mc.Spec.Credential,
Namespace: mc.Namespace,
}, cred)
if err != nil {
return ctrl.Result{}, err
}

if _, err = sveltos.ReconcileProfile(ctx, r.Client, mc.Namespace, mc.Name,
sveltos.ReconcileProfileOpts{
OwnerReference: &metav1.OwnerReference{
Expand All @@ -474,11 +520,14 @@ func (r *ClusterDeploymentReconciler) updateServices(ctx context.Context, mc *kc
kcm.FluxHelmChartNameKey: mc.Name,
},
},
HelmChartOpts: opts,
Priority: mc.Spec.ServiceSpec.Priority,
StopOnConflict: mc.Spec.ServiceSpec.StopOnConflict,
Reload: mc.Spec.ServiceSpec.Reload,
TemplateResourceRefs: mc.Spec.ServiceSpec.TemplateResourceRefs,
HelmChartOpts: opts,
Priority: mc.Spec.ServiceSpec.Priority,
StopOnConflict: mc.Spec.ServiceSpec.StopOnConflict,
Reload: mc.Spec.ServiceSpec.Reload,
TemplateResourceRefs: append(
getProjectTemplateResourceRefs(cred), mc.Spec.ServiceSpec.TemplateResourceRefs...,
),
PolicyRefs: getProjectPolicyRefs(cred),
}); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to reconcile Profile: %w", err)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/sveltos/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ReconcileProfileOpts struct {
LabelSelector metav1.LabelSelector
HelmChartOpts []HelmChartOpts
TemplateResourceRefs []sveltosv1beta1.TemplateResourceRef
PolicyRefs []sveltosv1beta1.PolicyRef
Priority int32
StopOnConflict bool
Reload bool
Expand Down Expand Up @@ -239,6 +240,7 @@ func GetSpec(opts *ReconcileProfileOpts) (*sveltosv1beta1.Spec, error) {
HelmCharts: make([]sveltosv1beta1.HelmChart, 0, len(opts.HelmChartOpts)),
Reloader: opts.Reload,
TemplateResourceRefs: opts.TemplateResourceRefs,
PolicyRefs: opts.PolicyRefs,
}

for _, hc := range opts.HelmChartOpts {
Expand Down

0 comments on commit 2bec5ed

Please sign in to comment.