Skip to content

Commit dcbf202

Browse files
committed
fix oci source use-case
1 parent 5145b5e commit dcbf202

File tree

3 files changed

+50
-30
lines changed

3 files changed

+50
-30
lines changed

api/crds/manifests/dns.openmcp.cloud_dnsserviceconfigs.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ spec:
103103
chartName:
104104
description: |-
105105
ChartName specifies the name of the external-dns chart.
106-
Depending on the source, this can also be a relative path within the repository.
107-
When using a source that needs a version (helm or oci), append the version to the chart name using '@', e.g. '[email protected]' or omit for latest version.
108-
minLength: 1
106+
Can be omitted for oci sources, required for git and helm sources.
107+
For git sources, this is the path within the git repository to the chart.
108+
For helm sources, append the version to the chart name using '@', e.g. '[email protected]' or omit for latest version.
109109
type: string
110110
git:
111111
description: |-
@@ -639,10 +639,11 @@ spec:
639639
- interval
640640
- url
641641
type: object
642-
required:
643-
- chartName
644642
type: object
645643
x-kubernetes-validations:
644+
- message: chartName must be set if git is used as source
645+
rule: '(has(self.git) || has(self.helm)) ? (has(self.chartName)
646+
&& size(self.chartName) > 0) : true'
646647
- message: exactly one of the fields in [helm git oci] must be set
647648
rule: '[has(self.helm),has(self.git),has(self.oci)].filter(x,x==true).size()
648649
== 1'

api/dns/v1alpha1/config_types.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ type SecretsToCopy struct {
4949
// Exactly one of 'HelmRepository', 'GitRepository' or 'OCIRepository' must be set.
5050
// If 'copyAuthSecret' is set, the referenced source secret is copied into the namespace where the Flux resources are created with the specified target name.
5151
// +kubebuilder:validation:ExactlyOneOf=helm;git;oci
52+
// +kubebuilder:validation:XValidation:rule="(has(self.git) || has(self.helm)) ? (has(self.chartName) && size(self.chartName) > 0) : true", message="chartName must be set if git is used as source"
5253
type ExternalDNSSource struct {
5354
// ChartName specifies the name of the external-dns chart.
54-
// Depending on the source, this can also be a relative path within the repository.
55-
// When using a source that needs a version (helm or oci), append the version to the chart name using '@', e.g. '[email protected]' or omit for latest version.
56-
// +kubebuilder:validation:MinLength=1
55+
// Can be omitted for oci sources, required for git and helm sources.
56+
// For git sources, this is the path within the git repository to the chart.
57+
// For helm sources, append the version to the chart name using '@', e.g. '[email protected]' or omit for latest version.
58+
// +optional
5759
ChartName string `json:"chartName"`
5860
Helm *fluxv1.HelmRepositorySpec `json:"helm,omitempty"`
5961
Git *fluxv1.GitRepositorySpec `json:"git,omitempty"`

internal/controllers/cluster/controller.go

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ import (
4747
dnsv1alpha1 "github.com/openmcp-project/platform-service-dns/api/dns/v1alpha1"
4848
)
4949

50-
const ControllerName = "DNSCluster"
51-
const defaultRequeueAfterDuration = 30 * time.Second
52-
const TargetClusterNamespace = "external-dns"
50+
const (
51+
ControllerName = "DNSCluster"
52+
defaultRequeueAfterDuration = 30 * time.Second
53+
TargetClusterNamespace = "external-dns"
54+
55+
SourceKindHelmRepository = "HelmRepository"
56+
SourceKindGitRepository = "GitRepository"
57+
SourceKindOCIRepository = "OCIRepository"
58+
)
5359

5460
type ClusterReconciler struct {
5561
PlatformCluster *clusters.Cluster
@@ -558,7 +564,7 @@ func (r *ClusterReconciler) deployHelmChartSource(ctx context.Context, c *cluste
558564
helmRepo.Spec = *rr.ProviderConfig.Spec.ExternalDNSSource.Helm.DeepCopy()
559565
return nil
560566
}
561-
rr.SourceKind = "HelmRepository"
567+
rr.SourceKind = SourceKindHelmRepository
562568
for i := range existingHelm.Items {
563569
obj := &existingHelm.Items[i]
564570
if obj.GetName() != sourceName {
@@ -577,7 +583,7 @@ func (r *ClusterReconciler) deployHelmChartSource(ctx context.Context, c *cluste
577583
gitRepo.Spec = *rr.ProviderConfig.Spec.ExternalDNSSource.Git.DeepCopy()
578584
return nil
579585
}
580-
rr.SourceKind = "GitRepository"
586+
rr.SourceKind = SourceKindGitRepository
581587
for i := range existingGit.Items {
582588
obj := &existingGit.Items[i]
583589
if obj.GetName() != sourceName {
@@ -596,7 +602,7 @@ func (r *ClusterReconciler) deployHelmChartSource(ctx context.Context, c *cluste
596602
ociRepo.Spec = *rr.ProviderConfig.Spec.ExternalDNSSource.OCI.DeepCopy()
597603
return nil
598604
}
599-
rr.SourceKind = "OCIRepository"
605+
rr.SourceKind = SourceKindOCIRepository
600606
for i := range existingOCI.Items {
601607
obj := &existingOCI.Items[i]
602608
if obj.GetName() != sourceName {
@@ -655,20 +661,31 @@ func (r *ClusterReconciler) deployHelmRelease(ctx context.Context, c *clustersv1
655661
// labels
656662
hr.Labels = maputils.Merge(hr.Labels, expectedLabels)
657663
// chart
658-
hr.Spec.Chart = &fluxhelmv2.HelmChartTemplate{
659-
Spec: fluxhelmv2.HelmChartTemplateSpec{
660-
SourceRef: fluxhelmv2.CrossNamespaceObjectReference{
661-
APIVersion: fluxsourcev1.SchemeBuilder.GroupVersion.String(),
662-
Kind: rr.SourceKind,
663-
Name: hr.Name,
664-
Namespace: hr.Namespace,
664+
if rr.SourceKind == SourceKindOCIRepository {
665+
hr.Spec.Chart = nil
666+
hr.Spec.ChartRef = &fluxhelmv2.CrossNamespaceSourceReference{
667+
APIVersion: fluxsourcev1.SchemeBuilder.GroupVersion.String(),
668+
Kind: rr.SourceKind,
669+
Name: hr.Name,
670+
Namespace: hr.Namespace,
671+
}
672+
} else {
673+
hr.Spec.ChartRef = nil
674+
hr.Spec.Chart = &fluxhelmv2.HelmChartTemplate{
675+
Spec: fluxhelmv2.HelmChartTemplateSpec{
676+
SourceRef: fluxhelmv2.CrossNamespaceObjectReference{
677+
APIVersion: fluxsourcev1.SchemeBuilder.GroupVersion.String(),
678+
Kind: rr.SourceKind,
679+
Name: hr.Name,
680+
Namespace: hr.Namespace,
681+
},
665682
},
666-
},
667-
}
668-
chartNameVersion := strings.Split(rr.ProviderConfig.Spec.ExternalDNSSource.ChartName, "@")
669-
hr.Spec.Chart.Spec.Chart = chartNameVersion[0]
670-
if len(chartNameVersion) > 1 {
671-
hr.Spec.Chart.Spec.Version = chartNameVersion[1]
683+
}
684+
chartNameVersion := strings.Split(rr.ProviderConfig.Spec.ExternalDNSSource.ChartName, "@")
685+
hr.Spec.Chart.Spec.Chart = chartNameVersion[0]
686+
if len(chartNameVersion) > 1 {
687+
hr.Spec.Chart.Spec.Version = chartNameVersion[1]
688+
}
672689
}
673690
// release information
674691
hr.Spec.ReleaseName = "external-dns"
@@ -797,19 +814,19 @@ func (r *ClusterReconciler) undeployHelmChartSource(ctx context.Context, c *clus
797814
toBeDeleted := []client.Object{}
798815
toBeDeleted = append(toBeDeleted, collections.ProjectSliceToSlice(existingHelm.Items, func(obj fluxsourcev1.HelmRepository) client.Object {
799816
if obj.GetObjectKind().GroupVersionKind().Kind == "" {
800-
obj.SetGroupVersionKind(schema.GroupVersionKind{Group: fluxsourcev1.GroupVersion.Group, Version: fluxsourcev1.GroupVersion.Version, Kind: "HelmRepository"})
817+
obj.SetGroupVersionKind(schema.GroupVersionKind{Group: fluxsourcev1.GroupVersion.Group, Version: fluxsourcev1.GroupVersion.Version, Kind: SourceKindHelmRepository})
801818
}
802819
return &obj
803820
})...)
804821
toBeDeleted = append(toBeDeleted, collections.ProjectSliceToSlice(existingGit.Items, func(obj fluxsourcev1.GitRepository) client.Object {
805822
if obj.GetObjectKind().GroupVersionKind().Kind == "" {
806-
obj.SetGroupVersionKind(schema.GroupVersionKind{Group: fluxsourcev1.GroupVersion.Group, Version: fluxsourcev1.GroupVersion.Version, Kind: "GitRepository"})
823+
obj.SetGroupVersionKind(schema.GroupVersionKind{Group: fluxsourcev1.GroupVersion.Group, Version: fluxsourcev1.GroupVersion.Version, Kind: SourceKindGitRepository})
807824
}
808825
return &obj
809826
})...)
810827
toBeDeleted = append(toBeDeleted, collections.ProjectSliceToSlice(existingOCI.Items, func(obj fluxsourcev1.OCIRepository) client.Object {
811828
if obj.GetObjectKind().GroupVersionKind().Kind == "" {
812-
obj.SetGroupVersionKind(schema.GroupVersionKind{Group: fluxsourcev1.GroupVersion.Group, Version: fluxsourcev1.GroupVersion.Version, Kind: "OCIRepository"})
829+
obj.SetGroupVersionKind(schema.GroupVersionKind{Group: fluxsourcev1.GroupVersion.Group, Version: fluxsourcev1.GroupVersion.Version, Kind: SourceKindOCIRepository})
813830
}
814831
return &obj
815832
})...)

0 commit comments

Comments
 (0)