Skip to content

Commit 294ea4c

Browse files
authored
Revise Feature crd (#213)
Signed-off-by: Tamal Saha <[email protected]>
1 parent e35b8dc commit 294ea4c

File tree

10 files changed

+164
-74
lines changed

10 files changed

+164
-74
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ require (
4343
kmodules.xyz/custom-resources v0.25.1
4444
kmodules.xyz/go-containerregistry v0.0.11
4545
kmodules.xyz/monitoring-agent-api v0.25.1
46-
kmodules.xyz/resource-metadata v0.17.6
46+
kmodules.xyz/resource-metadata v0.17.8
4747
kmodules.xyz/resource-metrics v0.25.2
4848
kmodules.xyz/sets v0.25.0
4949
kubeops.dev/scanner v0.0.12

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -2119,8 +2119,8 @@ kmodules.xyz/monitoring-agent-api v0.25.1 h1:E1H8U/vMfYQ8wevmJv6Lcj0Z4DF7cH3hZ2x
21192119
kmodules.xyz/monitoring-agent-api v0.25.1/go.mod h1:IphGzRWbuV00B3TLalcBs6+IlchSZVTwKDty+J3LLz4=
21202120
kmodules.xyz/offshoot-api v0.25.0 h1:Svq9da/+sg5afOjpgo9vx2J/Lu90Mo0aFxkdQmgKnGI=
21212121
kmodules.xyz/offshoot-api v0.25.0/go.mod h1:ysEBn7LJuT3+s8ynAQA/OG0BSsJugXa6KGtDLMRjlKo=
2122-
kmodules.xyz/resource-metadata v0.17.6 h1:XXBsIwdiu72UQFDw6JqmwsfgBk/cgNlYdpjCpQ1IDdo=
2123-
kmodules.xyz/resource-metadata v0.17.6/go.mod h1:gUy7cQ7QvB/SQ3upgsmS4BVxm5NLbJEXBI7M2CLSymA=
2122+
kmodules.xyz/resource-metadata v0.17.8 h1:V9cTYGDN8+iKH/jePLfbJZjAIgq30ySOjF2kIbxun74=
2123+
kmodules.xyz/resource-metadata v0.17.8/go.mod h1:gUy7cQ7QvB/SQ3upgsmS4BVxm5NLbJEXBI7M2CLSymA=
21242124
kmodules.xyz/resource-metrics v0.25.2 h1:BwCb6qyunvQBa0u8UUkw+wYG5/T4qtNtAKcHjSsk0JU=
21252125
kmodules.xyz/resource-metrics v0.25.2/go.mod h1:ZK/52NLuwMk+Jt0bmUtGQHtSxPLYYpsFILG7SJhYPg0=
21262126
kmodules.xyz/sets v0.25.0 h1:belY/3trp/M/CKc1TEteA40jb2uCIdwKHhjpvrIxG+8=

pkg/controllers/feature/feature_controller.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ type releaseStatus struct {
190190

191191
func (r *frReconciler) evaluateStatus(ctx context.Context) (featureStatus, error) {
192192
var status featureStatus
193-
if len(r.feature.Spec.Requirements.Resources) != 0 {
193+
if len(r.feature.Spec.ReadinessChecks.Resources) != 0 {
194194
satisfied, reason, err := r.checkRequiredResourcesExistence(ctx)
195195
if err != nil {
196196
return status, err
@@ -203,7 +203,7 @@ func (r *frReconciler) evaluateStatus(ctx context.Context) (featureStatus, error
203203
}
204204
}
205205

206-
if len(r.feature.Spec.Requirements.Workloads) != 0 {
206+
if len(r.feature.Spec.ReadinessChecks.Workloads) != 0 {
207207
satisfied, reason, err := r.checkRequiredWorkloadExistence(ctx)
208208
if err != nil {
209209
return status, err
@@ -341,7 +341,7 @@ func (r *frReconciler) checkDependencyExistence(ctx context.Context) (bool, stri
341341
}
342342

343343
func (r *frReconciler) checkRequiredResourcesExistence(ctx context.Context) (bool, string, error) {
344-
for _, gvk := range r.feature.Spec.Requirements.Resources {
344+
for _, gvk := range r.feature.Spec.ReadinessChecks.Resources {
345345
objList := unstructured.UnstructuredList{}
346346
objList.SetGroupVersionKind(schema.GroupVersionKind{
347347
Group: gvk.Group,
@@ -359,7 +359,7 @@ func (r *frReconciler) checkRequiredResourcesExistence(ctx context.Context) (boo
359359
}
360360

361361
func (r *frReconciler) checkRequiredWorkloadExistence(ctx context.Context) (bool, string, error) {
362-
for _, w := range r.feature.Spec.Requirements.Workloads {
362+
for _, w := range r.feature.Spec.ReadinessChecks.Workloads {
363363
objList := unstructured.UnstructuredList{}
364364
objList.SetGroupVersionKind(schema.GroupVersionKind{
365365
Group: w.Group,

pkg/controllers/feature/feature_controller_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestFeatureEnableStatus(t *testing.T) {
5757
}{
5858
"Should be false when required resources does not exist": {
5959
feature: sampleFeature(func(in *uiapi.Feature) {
60-
in.Spec.Requirements.Resources = []metav1.GroupVersionKind{
60+
in.Spec.ReadinessChecks.Resources = []metav1.GroupVersionKind{
6161
{
6262
Group: "foo.io",
6363
Version: "v1",
@@ -69,7 +69,7 @@ func TestFeatureEnableStatus(t *testing.T) {
6969
},
7070
"Should be true when required workload exist": {
7171
feature: sampleFeature(func(in *uiapi.Feature) {
72-
in.Spec.Requirements.Workloads = []uiapi.WorkloadInfo{
72+
in.Spec.ReadinessChecks.Workloads = []uiapi.WorkloadInfo{
7373
{
7474
GroupVersionKind: metav1.GroupVersionKind{
7575
Group: "apps",
@@ -85,7 +85,7 @@ func TestFeatureEnableStatus(t *testing.T) {
8585
},
8686
"Should be true when required workload does not exist but HelmRelease exist": {
8787
feature: sampleFeature(func(in *uiapi.Feature) {
88-
in.Spec.Requirements.Workloads = []uiapi.WorkloadInfo{
88+
in.Spec.ReadinessChecks.Workloads = []uiapi.WorkloadInfo{
8989
{
9090
GroupVersionKind: metav1.GroupVersionKind{
9191
Group: "apps",
@@ -101,7 +101,7 @@ func TestFeatureEnableStatus(t *testing.T) {
101101
},
102102
"Should be false when neither workload nor HelmRelease exist": {
103103
feature: sampleFeature(func(in *uiapi.Feature) {
104-
in.Spec.Requirements.Workloads = []uiapi.WorkloadInfo{
104+
in.Spec.ReadinessChecks.Workloads = []uiapi.WorkloadInfo{
105105
{
106106
GroupVersionKind: metav1.GroupVersionKind{
107107
Group: "apps",
@@ -160,7 +160,7 @@ func TestFeatureReadyStatus(t *testing.T) {
160160
"Should not be ready when dependency is not satisfied": {
161161
feature: sampleFeature(func(in *uiapi.Feature) {
162162
in.Spec.Requirements.Features = []string{"foo", "bar"}
163-
in.Spec.Requirements.Workloads = []uiapi.WorkloadInfo{
163+
in.Spec.ReadinessChecks.Workloads = []uiapi.WorkloadInfo{
164164
{
165165
GroupVersionKind: metav1.GroupVersionKind{
166166
Group: "apps",
@@ -177,7 +177,7 @@ func TestFeatureReadyStatus(t *testing.T) {
177177
},
178178
"Should not be ready when the workload does not exit": {
179179
feature: sampleFeature(func(in *uiapi.Feature) {
180-
in.Spec.Requirements.Workloads = []uiapi.WorkloadInfo{
180+
in.Spec.ReadinessChecks.Workloads = []uiapi.WorkloadInfo{
181181
{
182182
GroupVersionKind: metav1.GroupVersionKind{
183183
Group: "apps",
@@ -193,7 +193,7 @@ func TestFeatureReadyStatus(t *testing.T) {
193193
},
194194
"Should not be ready when workload exist but HelmRelease does not exist": {
195195
feature: sampleFeature(func(in *uiapi.Feature) {
196-
in.Spec.Requirements.Workloads = []uiapi.WorkloadInfo{
196+
in.Spec.ReadinessChecks.Workloads = []uiapi.WorkloadInfo{
197197
{
198198
GroupVersionKind: metav1.GroupVersionKind{
199199
Group: "apps",
@@ -209,7 +209,7 @@ func TestFeatureReadyStatus(t *testing.T) {
209209
},
210210
"Should not be ready when workload exist but HelmRelease is not ready ": {
211211
feature: sampleFeature(func(in *uiapi.Feature) {
212-
in.Spec.Requirements.Workloads = []uiapi.WorkloadInfo{
212+
in.Spec.ReadinessChecks.Workloads = []uiapi.WorkloadInfo{
213213
{
214214
GroupVersionKind: metav1.GroupVersionKind{
215215
Group: "apps",
@@ -233,7 +233,7 @@ func TestFeatureReadyStatus(t *testing.T) {
233233
},
234234
"Should be ready when workload exist and HelmRelease is ready": {
235235
feature: sampleFeature(func(in *uiapi.Feature) {
236-
in.Spec.Requirements.Workloads = []uiapi.WorkloadInfo{
236+
in.Spec.ReadinessChecks.Workloads = []uiapi.WorkloadInfo{
237237
{
238238
GroupVersionKind: metav1.GroupVersionKind{
239239
Group: "apps",
@@ -311,7 +311,7 @@ func TestFeatureManagedStatus(t *testing.T) {
311311
}{
312312
"Managed should be true when HelmRelease exist": {
313313
feature: sampleFeature(func(in *uiapi.Feature) {
314-
in.Spec.Requirements.Workloads = []uiapi.WorkloadInfo{
314+
in.Spec.ReadinessChecks.Workloads = []uiapi.WorkloadInfo{
315315
{
316316
GroupVersionKind: metav1.GroupVersionKind{
317317
Group: "apps",
@@ -328,7 +328,7 @@ func TestFeatureManagedStatus(t *testing.T) {
328328
},
329329
"Managed should be false when HelmRelease does not exist": {
330330
feature: sampleFeature(func(in *uiapi.Feature) {
331-
in.Spec.Requirements.Workloads = []uiapi.WorkloadInfo{
331+
in.Spec.ReadinessChecks.Workloads = []uiapi.WorkloadInfo{
332332
{
333333
GroupVersionKind: metav1.GroupVersionKind{
334334
Group: "apps",

vendor/kmodules.xyz/resource-metadata/apis/ui/v1alpha1/feature_types.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1alpha1
1919
import (
2020
v1 "kmodules.xyz/client-go/api/v1"
2121

22+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
helmshared "x-helm.dev/apimachinery/apis/shared"
2425
)
@@ -50,7 +51,7 @@ type Feature struct {
5051
}
5152

5253
type FeatureSpec struct {
53-
// Title specify the title of this feature.
54+
// Title specifies the title of this feature.
5455
Title string `json:"title"`
5556
// Description specifies a short description of the service this feature provides.
5657
Description string `json:"description"`
@@ -59,21 +60,33 @@ type FeatureSpec struct {
5960
Icons []helmshared.ImageSpec `json:"icons,omitempty"`
6061
// FeatureSet specifies the name of the FeatureSet where this feature belong to.
6162
FeatureSet string `json:"featureSet"`
62-
// Required specify whether this feature is mandatory or not for enabling the respecting FeatureSet.
63+
// FeatureBlock specifies the ui block name of this feature.
64+
// +optional
65+
FeatureBlock string `json:"featureBlock,omitempty"`
66+
// Required specifies whether this feature is mandatory or not for enabling the respecting FeatureSet.
6367
// +optional
6468
Required bool `json:"required,omitempty"`
65-
// Requirements specifies the requirements for this feature to consider enabled.
69+
// Requirements specifies the requirements to enable this feature.
6670
// +optional
6771
Requirements Requirements `json:"requirements,omitempty"`
72+
// ReadinessChecks specifies the conditions for this feature to be considered enabled.
73+
// +optional
74+
ReadinessChecks ReadinessChecks `json:"readinessChecks,omitempty"`
6875
// Chart specifies the chart information that will be used by the FluxCD to install the respective feature
6976
// +optional
7077
Chart ChartInfo `json:"chart,omitempty"`
78+
// Values holds the values for this Helm release.
79+
// +optional
80+
Values *apiextensionsv1.JSON `json:"values,omitempty"`
7181
}
7282

7383
type Requirements struct {
7484
// Features specifies a list of Feature names that must be enabled for using this feature.
7585
// +optional
7686
Features []string `json:"features,omitempty"`
87+
}
88+
89+
type ReadinessChecks struct {
7790
// Resources specifies the resources that should be registered to consider this feature as enabled.
7891
// +optional
7992
Resources []metav1.GroupVersionKind `json:"resources,omitempty"`

vendor/kmodules.xyz/resource-metadata/apis/ui/v1alpha1/openapi_generated.go

+52-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)