Skip to content

Commit 938e70f

Browse files
KPostOfficeopenshift-merge-robot
authored andcommitted
Don't add default values to config map if not specified.
This allows MCAD to determine what an undefined value means Signed-off-by: Kevin <[email protected]>
1 parent a91ebbd commit 938e70f

File tree

11 files changed

+89
-15
lines changed

11 files changed

+89
-15
lines changed

api/v1alpha1/mcad_types.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,14 @@ type MCADSpec struct {
3939
PreemptionEnabled bool `json:"preemptionEnabled,omitempty"`
4040

4141
// AgentConfigs TODO: Add details
42-
// +kubebuilder:default=null
4342
AgentConfigs string `json:"agentConfigs,omitempty"`
4443

4544
// QuotaRestURL TODO: Add details
46-
// +kubebuilder:default=null
4745
QuotaRestURL string `json:"quotaRestURL,omitempty"`
4846

4947
// PodCreationTimeout TODO: Add details and confirm values
50-
// +kubebuilder:default=300
48+
// +kubebuilder:default=-1
5149
PodCreationTimeout int `json:"podCreationTimeout,omitempty"`
52-
//podCreationTimeout: //int (default blank)
53-
5450
}
5551

5652
// MCADStatus defines the observed state of MCAD

config/crd/bases/codeflare.codeflare.dev_mcads.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ spec:
3636
description: MCADSpec defines the desired state of MCAD
3737
properties:
3838
agentConfigs:
39-
default: "null"
4039
description: 'AgentConfigs TODO: Add details'
4140
type: string
4241
dispatcherMode:
@@ -55,7 +54,7 @@ spec:
5554
to multiple clusters.
5655
type: boolean
5756
podCreationTimeout:
58-
default: 300
57+
default: -1
5958
description: 'PodCreationTimeout TODO: Add details and confirm values'
6059
type: integer
6160
preemptionEnabled:
@@ -64,7 +63,6 @@ spec:
6463
preempted for others
6564
type: boolean
6665
quotaRestURL:
67-
default: "null"
6866
description: 'QuotaRestURL TODO: Add details'
6967
type: string
7068
type: object

config/internal/mcad/configmap.yaml.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
apiVersion: v1
22
data:
33
DISPATCHER_MODE: "{{.DispatcherMode}}"
4-
DISPATCHER_AGENT_CONFIGS: "{{.AgentConfigs}}"
54
PREEMPTION: "{{.PreemptionEnabled}}"
6-
QUOTA_REST_URL: "{{.QuotaRestURL}}"
7-
DISPATCH_RESOURCE_RESERVATION_TIMEOUT: "{{.PodCreationTimeout}}"
5+
{{if ne .AgentConfigs ""}}DISPATCHER_AGENT_CONFIGS: "{{.AgentConfigs}}"{{end}}
6+
{{if ne .QuotaRestURL ""}}QUOTA_REST_URL: "{{.QuotaRestURL}}"{{end}}
7+
{{if ne .PodCreationTimeout -1}}DISPATCH_RESOURCE_RESERVATION_TIMEOUT: "{{.PodCreationTimeout}}"{{end}}
88
kind: ConfigMap
99
metadata:
1010
name: mcad-{{.Name}}-config

controllers/mcad_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ type MCADReconciler struct {
4747
}
4848

4949
func (r *MCADReconciler) Apply(owner mf.Owner, params *MCADParams, template string, fns ...mf.Transformer) error {
50-
5150
tmplManifest, err := config.Manifest(r.Client, r.TemplatesPath+template, params, template, r.Log)
5251
if err != nil {
5352
return fmt.Errorf("error loading template yaml: %w", err)
@@ -84,6 +83,7 @@ func (r *MCADReconciler) ApplyWithoutOwner(params *MCADParams, template string,
8483
if err = tmplManifest.Apply(); err != nil {
8584
return err
8685
}
86+
8787
return nil
8888
}
8989

controllers/mcad_controller_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package controllers
22

33
import (
44
"context"
5+
56
mfc "github.com/manifestival/controller-runtime-client"
67
mf "github.com/manifestival/manifestival"
78
. "github.com/onsi/ginkgo/v2"
@@ -16,6 +17,13 @@ const (
1617
mcadServiceAccount1 = "./testdata/mcad_test_results/case_1/serviceaccount.yaml"
1718
)
1819

20+
const (
21+
mcadCRCase2 = "./testdata/mcad_test_cases/case_2.yaml"
22+
mcadConfigMap2 = "./testdata/mcad_test_results/case_2/configmap.yaml"
23+
mcadService2 = "./testdata/mcad_test_results/case_2/service.yaml"
24+
mcadServiceAccount2 = "./testdata/mcad_test_results/case_2/serviceaccount.yaml"
25+
)
26+
1927
func deployMCAD(ctx context.Context, path string, opts mf.Option) {
2028
mcad := &codeflarev1alpha1.MCAD{}
2129
err := convertToStructuredResource(path, mcad, opts)
@@ -38,4 +46,13 @@ var _ = Describe("The MCAD Controller", func() {
3846
})
3947
})
4048

49+
Context("In a namespace, when a populated MCAD Custom Resource is deployed", func() {
50+
51+
It("It should create a configmap", func() {
52+
deployMCAD(ctx, mcadCRCase2, opts)
53+
compareConfigMaps(mcadConfigMap2, opts)
54+
compareServiceAccounts(mcadServiceAccount2, opts)
55+
compareServices(mcadService2, opts)
56+
})
57+
})
4158
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: codeflare.codeflare.dev/v1alpha1
2+
kind: MCAD
3+
metadata:
4+
name: populated-custom-resource
5+
spec:
6+
podCreationTimeout: 300
7+
quotaRestURL: 'bar.com'
8+
agentConfigs: 'foo'

controllers/testdata/mcad_test_results/case_1/configmap.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,5 @@ metadata:
77
app: mcad-blank-custom-resource
88
component: multi-cluster-app-dispatcher
99
data:
10-
DISPATCHER_AGENT_CONFIGS: 'null'
1110
DISPATCHER_MODE: 'false'
12-
DISPATCH_RESOURCE_RESERVATION_TIMEOUT: '300'
1311
PREEMPTION: 'false'
14-
QUOTA_REST_URL: 'null'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
kind: ConfigMap
2+
apiVersion: v1
3+
metadata:
4+
name: mcad-populated-custom-resource-config
5+
namespace: default
6+
labels:
7+
app: mcad-populated-custom-resource
8+
component: multi-cluster-app-dispatcher
9+
data:
10+
DISPATCHER_MODE: 'false'
11+
PREEMPTION: 'false'
12+
DISPATCHER_AGENT_CONFIGS: 'foo'
13+
DISPATCH_RESOURCE_RESERVATION_TIMEOUT: '300'
14+
QUOTA_REST_URL: 'bar.com'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
kind: RoleBinding
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
name: populated-custom-resource-custom-metrics-auth-reader
5+
namespace: default
6+
subjects:
7+
- kind: ServiceAccount
8+
name: mcad-controller-populated-custom-resource
9+
namespace: default
10+
roleRef:
11+
apiGroup: rbac.authorization.k8s.io
12+
kind: Role
13+
name: extension-apiserver-authentication-reader
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
kind: Service
2+
apiVersion: v1
3+
metadata:
4+
name: mcad-populated-custom-resource-metrics
5+
namespace: default
6+
spec:
7+
clusterIP: 172.31.181.101
8+
ipFamilies:
9+
- IPv4
10+
ports:
11+
- name: https
12+
protocol: TCP
13+
port: 443
14+
targetPort: 6443
15+
- name: http
16+
protocol: TCP
17+
port: 80
18+
targetPort: 8080
19+
internalTrafficPolicy: Cluster
20+
clusterIPs:
21+
- 172.31.181.101
22+
type: ClusterIP
23+
ipFamilyPolicy: SingleStack
24+
sessionAffinity: None
25+
selector:
26+
app: mcad-populated-custom-resource
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: ServiceAccount
2+
apiVersion: v1
3+
metadata:
4+
name: mcad-controller-populated-custom-resource
5+
namespace: default

0 commit comments

Comments
 (0)