Skip to content

Commit fc81421

Browse files
authored
Merge pull request #14 from jerrinfrancis/fix/remove-mandatory-api
fix: migrate to two-state field markers — remove Mandatory()
2 parents 3ca5777 + 75fc88c commit fc81421

68 files changed

Lines changed: 676 additions & 688 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

components/crontask.go

Lines changed: 80 additions & 76 deletions
Large diffs are not rendered by default.

components/daemon.go

Lines changed: 67 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,35 @@ import (
2424
// It describes a DaemonSet which runs on every node in the cluster.
2525
func Daemon() *defkit.ComponentDefinition {
2626
// Use StringKeyMap for labels and annotations (generates [string]: string)
27-
labels := defkit.StringKeyMap("labels").Description("Specify the labels in the workload")
28-
annotations := defkit.StringKeyMap("annotations").Description("Specify the annotations in the workload")
27+
labels := defkit.StringKeyMap("labels").Optional().Description("Specify the labels in the workload")
28+
annotations := defkit.StringKeyMap("annotations").Optional().Description("Specify the annotations in the workload")
2929

30-
image := defkit.String("image").Mandatory().Description("Which image would you like to use for your service").Short("i")
30+
image := defkit.String("image").Description("Which image would you like to use for your service").Short("i")
3131

3232
// Use Enum for imagePullPolicy to generate proper CUE enum type
3333
imagePullPolicy := defkit.Enum("imagePullPolicy").
34+
Optional().
3435
Values("Always", "Never", "IfNotPresent").
3536
Description("Specify image pull policy for your service")
3637

3738
imagePullSecrets := defkit.StringList("imagePullSecrets").
39+
Optional().
3840
Description("Specify image pull secrets for your service")
3941

4042
// Structured ports array matching original CUE
4143
ports := defkit.Array("ports").
44+
Optional().
4245
Description("Which ports do you want customer traffic sent to, defaults to 80").
4346
WithFields(
44-
defkit.Int("port").Mandatory().Description("Number of port to expose on the pod's IP address"),
45-
defkit.String("name").Description("Name of the port"),
47+
defkit.Int("port").Description("Number of port to expose on the pod's IP address"),
48+
defkit.String("name").Optional().Description("Name of the port"),
4649
defkit.Enum("protocol").Values("TCP", "UDP", "SCTP").Default("TCP").Description("Protocol for port. Must be UDP, TCP, or SCTP"),
4750
defkit.Bool("expose").Default(false).Description("Specify if the port should be exposed"),
4851
)
4952

5053
// Deprecated port parameter - fallback for older definitions
5154
port := defkit.Int("port").
55+
Optional().
5256
Ignore().
5357
Description("Deprecated field, please use ports instead").
5458
Short("p")
@@ -64,106 +68,108 @@ func Daemon() *defkit.ComponentDefinition {
6468
Ignore().
6569
Description("If addRevisionLabel is true, the revision label will be added to the underlying pods")
6670

67-
cmd := defkit.StringList("cmd").Description("Commands to run in the container")
71+
cmd := defkit.StringList("cmd").Optional().Description("Commands to run in the container")
6872

6973
// Structured env array with detailed valueFrom schema
7074
env := defkit.List("env").
75+
Optional().
7176
Description("Define arguments by using environment variables").
7277
WithFields(
73-
defkit.String("name").Mandatory().Description("Environment variable name"),
74-
defkit.String("value").Description("The value of the environment variable"),
75-
defkit.Object("valueFrom").Description("Specifies a source the value of this var should come from").
78+
defkit.String("name").Description("Environment variable name"),
79+
defkit.String("value").Optional().Description("The value of the environment variable"),
80+
defkit.Object("valueFrom").Optional().Description("Specifies a source the value of this var should come from").
7681
WithFields(
77-
defkit.Object("secretKeyRef").Description("Selects a key of a secret in the pod's namespace").
82+
defkit.Object("secretKeyRef").Optional().Description("Selects a key of a secret in the pod's namespace").
7883
WithFields(
79-
defkit.String("name").Mandatory().Description("The name of the secret in the pod's namespace to select from"),
80-
defkit.String("key").Mandatory().Description("The key of the secret to select from. Must be a valid secret key"),
84+
defkit.String("name").Description("The name of the secret in the pod's namespace to select from"),
85+
defkit.String("key").Description("The key of the secret to select from. Must be a valid secret key"),
8186
),
82-
defkit.Object("configMapKeyRef").Description("Selects a key of a config map in the pod's namespace").
87+
defkit.Object("configMapKeyRef").Optional().Description("Selects a key of a config map in the pod's namespace").
8388
WithFields(
84-
defkit.String("name").Mandatory().Description("The name of the config map in the pod's namespace to select from"),
85-
defkit.String("key").Mandatory().Description("The key of the config map to select from. Must be a valid secret key"),
89+
defkit.String("name").Description("The name of the config map in the pod's namespace to select from"),
90+
defkit.String("key").Description("The key of the config map to select from. Must be a valid secret key"),
8691
),
8792
),
8893
)
8994

90-
cpu := defkit.String("cpu").Description("Number of CPU units for the service, like `0.5` (0.5 CPU core), `1` (1 CPU core)")
91-
memory := defkit.String("memory").Description("Specifies the attributes of the memory resource required for the container.")
95+
cpu := defkit.String("cpu").Optional().Description("Number of CPU units for the service, like `0.5` (0.5 CPU core), `1` (1 CPU core)")
96+
memory := defkit.String("memory").Optional().Description("Specifies the attributes of the memory resource required for the container.")
9297

9398
// VolumeMounts with detailed schemas using fluent API
9499
volumeMounts := defkit.Object("volumeMounts").
100+
Optional().
95101
WithFields(
96-
defkit.List("pvc").Description("Mount PVC type volume").WithFields(
97-
defkit.String("name").Mandatory(),
98-
defkit.String("mountPath").Mandatory(),
99-
defkit.String("claimName").Mandatory().Description("The name of the PVC"),
102+
defkit.List("pvc").Optional().Description("Mount PVC type volume").WithFields(
103+
defkit.String("name"),
104+
defkit.String("mountPath"),
105+
defkit.String("claimName").Description("The name of the PVC"),
100106
),
101-
defkit.List("configMap").Description("Mount ConfigMap type volume").WithFields(
102-
defkit.String("name").Mandatory(),
103-
defkit.String("mountPath").Mandatory(),
107+
defkit.List("configMap").Optional().Description("Mount ConfigMap type volume").WithFields(
108+
defkit.String("name"),
109+
defkit.String("mountPath"),
104110
defkit.Int("defaultMode").Default(420),
105-
defkit.String("cmName").Mandatory(),
106-
defkit.List("items").WithFields(
107-
defkit.String("key").Mandatory(),
108-
defkit.String("path").Mandatory(),
111+
defkit.String("cmName"),
112+
defkit.List("items").Optional().WithFields(
113+
defkit.String("key"),
114+
defkit.String("path"),
109115
defkit.Int("mode").Default(511),
110116
),
111117
),
112-
defkit.List("secret").Description("Mount Secret type volume").WithFields(
113-
defkit.String("name").Mandatory(),
114-
defkit.String("mountPath").Mandatory(),
118+
defkit.List("secret").Optional().Description("Mount Secret type volume").WithFields(
119+
defkit.String("name"),
120+
defkit.String("mountPath"),
115121
defkit.Int("defaultMode").Default(420),
116-
defkit.String("secretName").Mandatory(),
117-
defkit.List("items").WithFields(
118-
defkit.String("key").Mandatory(),
119-
defkit.String("path").Mandatory(),
122+
defkit.String("secretName"),
123+
defkit.List("items").Optional().WithFields(
124+
defkit.String("key"),
125+
defkit.String("path"),
120126
defkit.Int("mode").Default(511),
121127
),
122128
),
123-
defkit.List("emptyDir").Description("Mount EmptyDir type volume").WithFields(
124-
defkit.String("name").Mandatory(),
125-
defkit.String("mountPath").Mandatory(),
129+
defkit.List("emptyDir").Optional().Description("Mount EmptyDir type volume").WithFields(
130+
defkit.String("name"),
131+
defkit.String("mountPath"),
126132
defkit.Enum("medium").Values("", "Memory").Default(""),
127133
),
128-
defkit.List("hostPath").Description("Mount HostPath type volume").WithFields(
129-
defkit.String("name").Mandatory(),
130-
defkit.String("mountPath").Mandatory(),
131-
defkit.Enum("mountPropagation").Values("None", "HostToContainer", "Bidirectional"),
132-
defkit.String("path").Mandatory(),
133-
defkit.Bool("readOnly"),
134+
defkit.List("hostPath").Optional().Description("Mount HostPath type volume").WithFields(
135+
defkit.String("name"),
136+
defkit.String("mountPath"),
137+
defkit.Enum("mountPropagation").Optional().Values("None", "HostToContainer", "Bidirectional"),
138+
defkit.String("path"),
139+
defkit.Bool("readOnly").Optional(),
134140
),
135141
)
136142

137143
// Deprecated volumes parameter - discriminated union with type-based conditional fields
138-
volumes := defkit.List("volumes").Description("Deprecated field, use volumeMounts instead.").
144+
volumes := defkit.List("volumes").Optional().Description("Deprecated field, use volumeMounts instead.").
139145
WithFields(
140-
defkit.String("name").Mandatory(),
141-
defkit.String("mountPath").Mandatory(),
146+
defkit.String("name"),
147+
defkit.String("mountPath"),
142148
defkit.OneOf("type").
143149
Description("Specify volume type, options: \"pvc\",\"configMap\",\"secret\",\"emptyDir\", default to emptyDir").
144150
Default("emptyDir").
145151
Variants(
146152
defkit.Variant("pvc").WithFields(
147-
defkit.Field("claimName", defkit.ParamTypeString).Mandatory(),
153+
defkit.Field("claimName", defkit.ParamTypeString),
148154
),
149155
defkit.Variant("configMap").WithFields(
150156
defkit.Field("defaultMode", defkit.ParamTypeInt).Default(420),
151-
defkit.Field("cmName", defkit.ParamTypeString).Mandatory(),
152-
defkit.Field("items", defkit.ParamTypeArray).Nested(
157+
defkit.Field("cmName", defkit.ParamTypeString),
158+
defkit.Field("items", defkit.ParamTypeArray).Optional().Nested(
153159
defkit.Struct("").WithFields(
154-
defkit.Field("key", defkit.ParamTypeString).Mandatory(),
155-
defkit.Field("path", defkit.ParamTypeString).Mandatory(),
160+
defkit.Field("key", defkit.ParamTypeString),
161+
defkit.Field("path", defkit.ParamTypeString),
156162
defkit.Field("mode", defkit.ParamTypeInt).Default(511),
157163
),
158164
),
159165
),
160166
defkit.Variant("secret").WithFields(
161167
defkit.Field("defaultMode", defkit.ParamTypeInt).Default(420),
162-
defkit.Field("secretName", defkit.ParamTypeString).Mandatory(),
163-
defkit.Field("items", defkit.ParamTypeArray).Nested(
168+
defkit.Field("secretName", defkit.ParamTypeString),
169+
defkit.Field("items", defkit.ParamTypeArray).Optional().Nested(
164170
defkit.Struct("").WithFields(
165-
defkit.Field("key", defkit.ParamTypeString).Mandatory(),
166-
defkit.Field("path", defkit.ParamTypeString).Mandatory(),
171+
defkit.Field("key", defkit.ParamTypeString),
172+
defkit.Field("path", defkit.ParamTypeString),
167173
defkit.Field("mode", defkit.ParamTypeInt).Default(511),
168174
),
169175
),
@@ -176,18 +182,21 @@ func Daemon() *defkit.ComponentDefinition {
176182

177183
// Health probes referencing the helper definition
178184
livenessProbe := defkit.Object("livenessProbe").
185+
Optional().
179186
Description("Instructions for assessing whether the container is alive.").
180187
WithSchemaRef("HealthProbe")
181188
readinessProbe := defkit.Object("readinessProbe").
189+
Optional().
182190
Description("Instructions for assessing whether the container is in a suitable state to serve traffic.").
183191
WithSchemaRef("HealthProbe")
184192

185193
// Structured hostAliases with required hostnames
186194
hostAliases := defkit.List("hostAliases").
195+
Optional().
187196
Description("Specify the hostAliases to add").
188197
WithFields(
189-
defkit.String("ip").Mandatory(),
190-
defkit.StringList("hostnames").Mandatory(),
198+
defkit.String("ip"),
199+
defkit.StringList("hostnames"),
191200
)
192201

193202
return defkit.NewComponent("daemon").

components/schemas.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@ import (
2626
func HealthProbeParam() *defkit.MapParam {
2727
return defkit.Object("probe").
2828
WithFields(
29-
defkit.Object("exec").Description("Instructions for assessing container health by executing a command. Either this attribute or the httpGet attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the httpGet attribute and the tcpSocket attribute.").
29+
defkit.Object("exec").Optional().Description("Instructions for assessing container health by executing a command. Either this attribute or the httpGet attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the httpGet attribute and the tcpSocket attribute.").
3030
WithFields(
31-
defkit.StringList("command").Mandatory().Description("A command to be executed inside the container to assess its health. Each space delimited token of the command is a separate array element. Commands exiting 0 are considered to be successful probes, whilst all other exit codes are considered failures."),
31+
defkit.StringList("command").Description("A command to be executed inside the container to assess its health. Each space delimited token of the command is a separate array element. Commands exiting 0 are considered to be successful probes, whilst all other exit codes are considered failures."),
3232
),
33-
defkit.Object("httpGet").Description("Instructions for assessing container health by executing an HTTP GET request. Either this attribute or the exec attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the tcpSocket attribute.").
33+
defkit.Object("httpGet").Optional().Description("Instructions for assessing container health by executing an HTTP GET request. Either this attribute or the exec attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the tcpSocket attribute.").
3434
WithFields(
35-
defkit.String("path").Mandatory().Description("The endpoint, relative to the port, to which the HTTP GET request should be directed."),
36-
defkit.Int("port").Mandatory().Description("The TCP socket within the container to which the HTTP GET request should be directed."),
37-
defkit.String("host"),
38-
defkit.String("scheme").Default("HTTP").ForceOptional(),
39-
defkit.List("httpHeaders").WithFields(
40-
defkit.String("name").Mandatory(),
41-
defkit.String("value").Mandatory(),
35+
defkit.String("path").Description("The endpoint, relative to the port, to which the HTTP GET request should be directed."),
36+
defkit.Int("port").Description("The TCP socket within the container to which the HTTP GET request should be directed."),
37+
defkit.String("host").Optional(),
38+
defkit.String("scheme").Default("HTTP").Optional(),
39+
defkit.List("httpHeaders").Optional().WithFields(
40+
defkit.String("name"),
41+
defkit.String("value"),
4242
),
4343
),
44-
defkit.Object("tcpSocket").Description("Instructions for assessing container health by probing a TCP socket. Either this attribute or the exec attribute or the httpGet attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the httpGet attribute.").
44+
defkit.Object("tcpSocket").Optional().Description("Instructions for assessing container health by probing a TCP socket. Either this attribute or the exec attribute or the httpGet attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the httpGet attribute.").
4545
WithFields(
46-
defkit.Int("port").Mandatory().Description("The TCP socket within the container that should be probed to assess container health."),
46+
defkit.Int("port").Description("The TCP socket within the container that should be probed to assess container health."),
4747
),
4848
defkit.Int("initialDelaySeconds").Default(0).Description("Number of seconds after the container is started before the first probe is initiated."),
4949
defkit.Int("periodSeconds").Default(10).Description("How often, in seconds, to execute the probe."),

0 commit comments

Comments
 (0)