Skip to content

Commit ab54277

Browse files
Support passing feature-specific values for spoke clusters (#14)
Signed-off-by: Rokibul Hasan <mdrokibulhasan@appscode.com>
1 parent 590f0ce commit ab54277

File tree

4 files changed

+93
-3
lines changed

4 files changed

+93
-3
lines changed

apis/profile/v1alpha1/managedclusterprofilebinding_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const (
3232
type ManagedClusterProfileBindingSpec struct {
3333
ProfileRef core.LocalObjectReference `json:"profileRef"`
3434
ClusterMetadata kmapi.ClusterInfo `json:"clusterMetadata"`
35+
Features map[string]FeatureSpec `json:"features,omitempty"`
3536
}
3637

3738
type BindingStatusPhase string

apis/profile/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crds/profile.k8s.appscode.com_managedclusterprofilebindings.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,73 @@ spec:
6767
- name
6868
- uid
6969
type: object
70+
features:
71+
additionalProperties:
72+
properties:
73+
chart:
74+
properties:
75+
createNamespace:
76+
type: boolean
77+
name:
78+
type: string
79+
namespace:
80+
type: string
81+
sourceRef:
82+
properties:
83+
apiGroup:
84+
type: string
85+
kind:
86+
type: string
87+
name:
88+
type: string
89+
namespace:
90+
type: string
91+
required:
92+
- name
93+
type: object
94+
valuesFiles:
95+
items:
96+
type: string
97+
type: array
98+
version:
99+
type: string
100+
required:
101+
- name
102+
- sourceRef
103+
type: object
104+
featureSet:
105+
type: string
106+
values:
107+
x-kubernetes-preserve-unknown-fields: true
108+
valuesFrom:
109+
items:
110+
properties:
111+
kind:
112+
enum:
113+
- Secret
114+
- ConfigMap
115+
type: string
116+
name:
117+
maxLength: 253
118+
minLength: 1
119+
type: string
120+
optional:
121+
type: boolean
122+
targetPath:
123+
maxLength: 250
124+
pattern: ^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$
125+
type: string
126+
valuesKey:
127+
maxLength: 253
128+
pattern: ^[\-._a-zA-Z0-9]+$
129+
type: string
130+
required:
131+
- kind
132+
- name
133+
type: object
134+
type: array
135+
type: object
136+
type: object
70137
profileRef:
71138
properties:
72139
name:

pkg/feature_installer/enable_featureset.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ func enableFeatureSet(ctx context.Context, kc client.Client, featureSet string,
192192
return err
193193
}
194194

195-
return applyFeatureSet(ctx, kc, mw, fakeServer, featureSet, []string{"kube-ui-server"}, profile, &mc)
195+
return applyFeatureSet(ctx, kc, mw, fakeServer, featureSet, []string{"kube-ui-server"}, profile, &mc, profileBinding)
196196
}
197-
return applyFeatureSet(ctx, kc, mw, fakeServer, featureSet, features, profile, &mc)
197+
return applyFeatureSet(ctx, kc, mw, fakeServer, featureSet, features, profile, &mc, profileBinding)
198198
}
199199

200-
func applyFeatureSet(ctx context.Context, kc client.Client, mw *workv1.ManifestWork, fakeServer *FakeServer, featureSet string, features []string, profile *profilev1alpha1.ManagedClusterSetProfile, mc *v1.ManagedCluster) error {
200+
func applyFeatureSet(ctx context.Context, kc client.Client, mw *workv1.ManifestWork, fakeServer *FakeServer, featureSet string, features []string, profile *profilev1alpha1.ManagedClusterSetProfile, mc *v1.ManagedCluster, profileBinding *profilev1alpha1.ManagedClusterProfileBinding) error {
201201
logger := klog.FromContext(ctx)
202202
var err error
203203
var fsObj uiapi.FeatureSet
@@ -216,6 +216,21 @@ func applyFeatureSet(ctx context.Context, kc client.Client, mw *workv1.ManifestW
216216
// Update values based on user-provided inputs stored in the profile
217217
for _, f := range features {
218218
featureKey := getFeaturePathInValues(f)
219+
if profileBinding.Spec.Features != nil {
220+
if _, exist := profileBinding.Spec.Features[f]; exist {
221+
var valuesMap map[string]interface{}
222+
if profileBinding.Spec.Features[f].Values != nil {
223+
if err = json.Unmarshal(profileBinding.Spec.Features[f].Values.Raw, &valuesMap); err != nil {
224+
return err
225+
}
226+
if err = unstructured.SetNestedMap(model, valuesMap, "resources", featureKey, "spec", "values"); err != nil {
227+
return err
228+
}
229+
continue
230+
}
231+
}
232+
}
233+
219234
curValues, _, err := unstructured.NestedMap(model, "resources", featureKey, "spec", "values")
220235
if err != nil {
221236
return err

0 commit comments

Comments
 (0)