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 9, 2025
1 parent 8f8cb9f commit abe75a8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 45 additions & 1 deletion internal/controller/clusterdeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,49 @@ func (r *ClusterDeploymentReconciler) updateServices(ctx context.Context, mc *hm
return ctrl.Result{}, err
}

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

var (
templateResourceRefs []sveltosv1beta1.TemplateResourceRef
policyRefs []sveltosv1beta1.PolicyRef
)

if cred.Spec.IdentityRef != nil {
templateResourceRefs = []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",
},
}

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

templateResourceRefs = append(templateResourceRefs, mc.Spec.ServiceSpec.TemplateResourceRefs...)

if _, err = sveltos.ReconcileProfile(ctx, r.Client, mc.Namespace, mc.Name,
sveltos.ReconcileProfileOpts{
OwnerReference: &metav1.OwnerReference{
Expand All @@ -472,7 +515,8 @@ func (r *ClusterDeploymentReconciler) updateServices(ctx context.Context, mc *hm
Priority: mc.Spec.ServiceSpec.Priority,
StopOnConflict: mc.Spec.ServiceSpec.StopOnConflict,
Reload: mc.Spec.ServiceSpec.Reload,
TemplateResourceRefs: mc.Spec.ServiceSpec.TemplateResourceRefs,
TemplateResourceRefs: templateResourceRefs,
PolicyRefs: policyRefs,
}); 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 abe75a8

Please sign in to comment.