Skip to content

Commit 4555688

Browse files
authored
feat: update nstemplateset revisions status (codeready-toolchain#648)
* update nstemplateset revisions status
1 parent 71e61dd commit 4555688

File tree

8 files changed

+380
-38
lines changed

8 files changed

+380
-38
lines changed

controllers/nstemplateset/features.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package nstemplateset
22

33
import (
44
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
5+
"github.com/codeready-toolchain/toolchain-common/pkg/utils"
56
"k8s.io/utils/strings/slices"
67
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
7-
"strings"
88
)
99

1010
// shouldCreate checks if the object has a feature toggle annotation. If it does then check if the corresponding
@@ -22,15 +22,5 @@ func shouldCreate(toCreate runtimeclient.Object, nsTmplSet *toolchainv1alpha1.NS
2222
if !found {
2323
return false // No feature winners in the NSTemplateSet at all. Skip this object.
2424
}
25-
return slices.Contains(splitCommaSeparatedList(winners), feature)
26-
}
27-
28-
// splitCommaSeparatedList acts exactly the same as strings.Split(s, ",") but returns an empty slice for empty strings.
29-
// To be used when, for example, we want to get an empty slice for empty comma separated list:
30-
// strings.Split("", ",") returns [""] while splitCommaSeparatedList("") returns []
31-
func splitCommaSeparatedList(s string) []string {
32-
if len(s) == 0 {
33-
return []string{}
34-
}
35-
return strings.Split(s, ",")
25+
return slices.Contains(utils.SplitCommaSeparatedList(winners), feature)
3626
}

controllers/nstemplateset/features_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package nstemplateset
22

33
import (
4-
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
5-
"strings"
64
"testing"
75

6+
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
7+
88
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
99
"github.com/stretchr/testify/assert"
1010
)
@@ -98,12 +98,6 @@ func TestShouldCreate(t *testing.T) {
9898
}
9999
}
100100

101-
func TestReallySplit(t *testing.T) {
102-
assert.Empty(t, splitCommaSeparatedList(""))
103-
assert.Equal(t, strings.Split("1,2,3", ","), splitCommaSeparatedList("1,2,3"))
104-
assert.Equal(t, strings.Split("1", ","), splitCommaSeparatedList("1"))
105-
}
106-
107101
func p(s string) *string {
108102
return &s
109103
}

controllers/nstemplateset/nstemplateset_controller.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,18 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
136136
} else if createdOrUpdated {
137137
return reconcile.Result{}, nil // wait for cluster resources to be created
138138
}
139+
if err := r.status.updateStatusClusterResourcesRevisions(ctx, nsTmplSet); err != nil {
140+
return reconcile.Result{}, err
141+
}
139142

140143
if createdOrUpdated, err := r.namespaces.ensure(ctx, nsTmplSet); err != nil {
141144
logger.Error(err, "failed to either provision or update user namespaces")
142145
return reconcile.Result{}, err
143146
} else if createdOrUpdated {
144-
return reconcile.Result{}, nil // something in the watched resources has changed - wait for another reconcile
147+
return reconcile.Result{}, nil
148+
}
149+
if err := r.status.updateStatusNamespacesRevisions(ctx, nsTmplSet); err != nil {
150+
return reconcile.Result{}, err
145151
}
146152

147153
// update provisioned namespace list
@@ -154,7 +160,10 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
154160
logger.Error(err, "failed to either provision or update roles in space")
155161
return reconcile.Result{}, err
156162
} else if createdOrUpdated {
157-
return reconcile.Result{}, nil // something in the watched resources has changed - wait for another reconcile
163+
return reconcile.Result{}, nil
164+
}
165+
if err := r.status.updateStatusSpaceRolesRevisions(ctx, nsTmplSet); err != nil {
166+
return reconcile.Result{}, err
158167
}
159168

160169
return reconcile.Result{}, r.status.setStatusReady(ctx, nsTmplSet)

0 commit comments

Comments
 (0)