Skip to content

Commit c8c966c

Browse files
authored
fix: component creation without secrets (#69)
* fix: component creation without secrets On-behalf-of: Radek Schekalla (SAP) <[email protected]> Signed-off-by: Radek Schekalla (SAP) <[email protected]> * chore: bump version On-behalf-of: Radek Schekalla (SAP) <[email protected]> Signed-off-by: Radek Schekalla (SAP) <[email protected]> * chore: update comments in tests On-behalf-of: Radek Schekalla (SAP) <[email protected]> Signed-off-by: Radek Schekalla (SAP) <[email protected]> * chore: update func desc On-behalf-of: Radek Schekalla (SAP) <[email protected]> Signed-off-by: Radek Schekalla (SAP) <[email protected]> --------- Signed-off-by: Radek Schekalla (SAP) <[email protected]>
1 parent 331dd19 commit c8c966c

File tree

3 files changed

+69
-6
lines changed

3 files changed

+69
-6
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.1.3-dev
1+
v0.1.4

internal/controller/crossplane_controller.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ func buildComponents(ctx context.Context, client client.Client, xp *v1alpha1.Cro
368368
xpComp := &component.Crossplane{
369369
Enabled: enabled,
370370
Config: &xp.Spec,
371-
ChartPullSecretName: extractSecretNames(xpHelmChartPullSecrets)[0],
371+
ChartPullSecretName: extractFirstSecretName(xpHelmChartPullSecrets),
372372
ImagePullSecretNames: extractSecretNames(xpContainerImagePullSecrets),
373373
}
374374
comps = append(comps, xpComp)
@@ -509,6 +509,19 @@ func extractSecretNames(secrets []commonapi.LocalObjectReference) []string {
509509
return result
510510
}
511511

512+
// extractFirstSecretName extracts the first not-empty name from a slice of LocalObjectReference
513+
func extractFirstSecretName(secrets []commonapi.LocalObjectReference) string {
514+
if len(secrets) == 0 {
515+
return ""
516+
}
517+
for _, secret := range secrets {
518+
if secret.Name != "" {
519+
return secret.Name
520+
}
521+
}
522+
return ""
523+
}
524+
512525
// deduplicateSecretRefs removes duplicate secret references based on name
513526
func deduplicateSecretRefs(secrets []commonapi.LocalObjectReference) []commonapi.LocalObjectReference {
514527
if len(secrets) == 0 {

internal/controller/crossplane_controller_test.go

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,59 @@ func Test_buildComponents(t *testing.T) {
166166
args args
167167
want []juggler.Component
168168
wantErr error
169-
}{
169+
}{{
170+
name: "Crossplane and crossplane-provider components are built and enabled",
171+
args: args{
172+
ctx: rcontext.WithTenantNamespace(context.Background(), "tenant-namespace"),
173+
client: nil,
174+
setPodNamespace: true,
175+
xp: &v1alpha1.Crossplane{
176+
Spec: v1alpha1.CrossplaneSpec{
177+
Version: "v1.0.0",
178+
Providers: []*v1alpha1.CrossplaneProviderConfig{{Name: "provider-1", Version: "v0.1.0"}},
179+
},
180+
},
181+
pc: &v1alpha1.ProviderConfig{
182+
Spec: v1alpha1.ProviderConfigSpec{
183+
CrossplaneVersions: []v1alpha1.CrossplaneVersion{
184+
{
185+
Version: "v1.0.0",
186+
Chart: v1alpha1.ChartSpec{URL: "https://charts.example.com/1"},
187+
Image: v1alpha1.ImageSpec{URL: "https://images.example.com/1"},
188+
},
189+
{
190+
Version: "v2.0.0",
191+
Chart: v1alpha1.ChartSpec{URL: "https://charts.example.com/2"},
192+
Image: v1alpha1.ImageSpec{URL: "https://images.example.com/2"},
193+
},
194+
},
195+
Providers: v1alpha1.CrossplaneProviders{
196+
AvailableProviders: []v1alpha1.AvailableCrossplaneProvider{
197+
{Name: "provider-1", Versions: []string{"v0.1.0"}, Package: "crossplane/provider-aws:v0.1.0"},
198+
{Name: "provider-2", Versions: []string{"v0.1.0"}, Package: "crossplane/provider-other:v0.1.0"},
199+
},
200+
},
201+
},
202+
},
203+
enabled: true,
204+
},
205+
want: []juggler.Component{
206+
&component.Crossplane{
207+
Enabled: true,
208+
Config: &v1alpha1.CrossplaneSpec{
209+
Version: "v1.0.0",
210+
Providers: []*v1alpha1.CrossplaneProviderConfig{{Name: "provider-1", Version: "v0.1.0"}},
211+
},
212+
},
213+
&component.CrossplaneProvider{
214+
Enabled: true,
215+
Config: &v1alpha1.CrossplaneProviderConfig{Name: "provider-1", Version: "v0.1.0"},
216+
},
217+
},
218+
wantErr: nil,
219+
},
170220
{
171-
name: "Crossplane components are built and enabled",
221+
name: "Crossplane, crossplane-provider, platform-secret and secret components are built and enabled",
172222
args: args{
173223
ctx: rcontext.WithTenantNamespace(context.Background(), "tenant-namespace"),
174224
client: nil,
@@ -317,7 +367,7 @@ func Test_buildComponents(t *testing.T) {
317367
},
318368
want: []juggler.Component{
319369
// Components expected to be built containing ALL (platform)secrets from providerConfig,
320-
// regardless of whether they are used by Crossplane or its providers
370+
// regardless of whether they are used by Crossplane or its providers. Duplicates removed.
321371
&component.Crossplane{
322372
Enabled: true,
323373
Config: &v1alpha1.CrossplaneSpec{
@@ -354,7 +404,7 @@ func Test_buildComponents(t *testing.T) {
354404
wantErr: nil,
355405
},
356406
{
357-
name: "Crossplane components are built and NOT enabled",
407+
name: "Components are built and disabled (for deletion)",
358408
args: args{
359409
ctx: rcontext.WithTenantNamespace(context.Background(), "tenant-namespace"),
360410
client: nil,

0 commit comments

Comments
 (0)