Skip to content

Commit

Permalink
Fixing name (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljakimczuk authored Sep 14, 2023
1 parent 481dca4 commit bfc2afb
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project's packages adheres to [Semantic Versioning](http://semver.org/s

## [Unreleased]

### Fixed

- Use the right name for Chart CR to be deleted.

## [6.8.0] - 2023-07-06

### Added
Expand Down
6 changes: 3 additions & 3 deletions service/controller/app/resource/chart/desired.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ func (r *Resource) GetDesiredState(ctx context.Context, obj interface{}) (interf
return nil, microerror.Mask(err)
}

chartName := key.ChartName(cr, r.workloadClusterID)

if key.IsDeleted(cr) {
// Return empty chart CR so it is deleted.
chartCR := &v1alpha1.Chart{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name,
Name: chartName,
Namespace: r.chartNamespace,
},
}

return chartCR, nil
}

chartName := key.ChartName(cr, r.workloadClusterID)

config, err := generateConfig(ctx, cc.Clients.K8s.K8sClient(), cr, cc.Catalog, r.chartNamespace)
if err != nil {
return nil, microerror.Mask(err)
Expand Down
68 changes: 68 additions & 0 deletions service/controller/app/resource/chart/desired_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

func Test_Resource_GetDesiredState(t *testing.T) {
tm := metav1.NewTime(time.Now())
tests := []struct {
name string
obj *v1alpha1.App
Expand All @@ -36,6 +37,7 @@ func Test_Resource_GetDesiredState(t *testing.T) {
expectedChartStatus *controllercontext.ChartStatus
errorPattern *regexp.Regexp
error bool
workloadClusterId string
}{
{
name: "case 0: flawless flow",
Expand Down Expand Up @@ -768,6 +770,67 @@ func Test_Resource_GetDesiredState(t *testing.T) {
},
error: false,
},
{
name: "case 9: deleting CAPI workload cluster app",
obj: &v1alpha1.App{
ObjectMeta: metav1.ObjectMeta{
Name: "demo01-hello-world",
Namespace: "org-demo",
Labels: map[string]string{
"giantswarm.io/cluster": "demo01",
},
DeletionTimestamp: &tm,
},
Spec: v1alpha1.AppSpec{
Catalog: "giantswarm",
Name: "hello-world",
Namespace: "default",
Version: "1.0.0",
KubeConfig: v1alpha1.AppSpecKubeConfig{
Secret: v1alpha1.AppSpecKubeConfigSecret{
Name: "demo01-kubeconfig",
Namespace: "org-demo",
},
},
},
},
expectedChart: &v1alpha1.Chart{
ObjectMeta: metav1.ObjectMeta{
Name: "hello-world",
Namespace: "giantswarm",
},
},
workloadClusterId: "demo01",
},
{
name: "case 10: deleting CAPI management cluster app",
obj: &v1alpha1.App{
ObjectMeta: metav1.ObjectMeta{
Name: "demo01-security-bundle",
Namespace: "org-demo",
Labels: map[string]string{
"giantswarm.io/cluster": "demo01",
},
DeletionTimestamp: &tm,
},
Spec: v1alpha1.AppSpec{
Catalog: "giantswarm",
Name: "security-bundle",
Namespace: "security",
Version: "1.0.0",
KubeConfig: v1alpha1.AppSpecKubeConfig{
InCluster: true,
},
},
},
expectedChart: &v1alpha1.Chart{
ObjectMeta: metav1.ObjectMeta{
Name: "demo01-security-bundle",
Namespace: "giantswarm",
},
},
workloadClusterId: "demo01",
},
}

for _, tc := range tests {
Expand All @@ -793,6 +856,11 @@ func Test_Resource_GetDesiredState(t *testing.T) {
ChartNamespace: "giantswarm",
DependencyWaitTimeoutMinutes: 30,
}

if tc.workloadClusterId != "" {
c.WorkloadClusterID = tc.workloadClusterId
}

r, err := New(c)
if err != nil {
t.Fatalf("error == %#v, want nil", err)
Expand Down

0 comments on commit bfc2afb

Please sign in to comment.