Skip to content

Commit f0c48e6

Browse files
committed
plz: add support for env vars and secrets from cluster
1 parent fe488dd commit f0c48e6

File tree

6 files changed

+125
-1
lines changed

6 files changed

+125
-1
lines changed

api/v1alpha1/privateloadzone_types.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type PrivateLoadZoneSpec struct {
3838
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
3939
Image string `json:"image,omitempty"`
4040
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
41+
42+
Config PrivateLoadZoneConfig `json:"config,omitempty"`
4143
}
4244

4345
// PrivateLoadZoneStatus defines the observed state of PrivateLoadZone
@@ -66,6 +68,17 @@ type PrivateLoadZoneList struct {
6668
Items []PrivateLoadZone `json:"items"`
6769
}
6870

71+
type PrivateLoadZoneConfig struct {
72+
Secrets []PLZSecretsConfig `json:"secrets,omitempty"`
73+
}
74+
75+
type PLZSecretsConfig struct {
76+
// these definitions are copies from corev1.EnvFromSource - to be
77+
// re-packed into that struct during TestRun creation
78+
ConfigMapRef *corev1.ConfigMapEnvSource `json:"configMapRef,omitempty"`
79+
SecretRef *corev1.SecretEnvSource `json:"secretRef,omitempty"`
80+
}
81+
6982
func init() {
7083
SchemeBuilder.Register(&PrivateLoadZone{}, &PrivateLoadZoneList{})
7184
}
@@ -115,3 +128,12 @@ func (plz *PrivateLoadZone) Deregister(ctx context.Context, logger logr.Logger,
115128
func uuid() string {
116129
return guuid.New().String()
117130
}
131+
132+
func (plzConfig *PrivateLoadZoneConfig) ToEnvFromSource() []corev1.EnvFromSource {
133+
envFromSource := make([]corev1.EnvFromSource, len(plzConfig.Secrets))
134+
for i := range plzConfig.Secrets {
135+
envFromSource[i].ConfigMapRef = plzConfig.Secrets[i].ConfigMapRef
136+
envFromSource[i].SecretRef = plzConfig.Secrets[i].SecretRef
137+
}
138+
return envFromSource
139+
}

api/v1alpha1/zz_generated.deepcopy.go

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

charts/k6-operator/templates/crds/plz.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,32 @@ spec:
3131
type: object
3232
spec:
3333
properties:
34+
config:
35+
properties:
36+
secrets:
37+
items:
38+
properties:
39+
configMapRef:
40+
properties:
41+
name:
42+
default: ""
43+
type: string
44+
optional:
45+
type: boolean
46+
type: object
47+
x-kubernetes-map-type: atomic
48+
secretRef:
49+
properties:
50+
name:
51+
default: ""
52+
type: string
53+
optional:
54+
type: boolean
55+
type: object
56+
x-kubernetes-map-type: atomic
57+
type: object
58+
type: array
59+
type: object
3460
image:
3561
type: string
3662
imagePullSecrets:

config/crd/bases/k6.io_privateloadzones.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,32 @@ spec:
2626
type: object
2727
spec:
2828
properties:
29+
config:
30+
properties:
31+
secrets:
32+
items:
33+
properties:
34+
configMapRef:
35+
properties:
36+
name:
37+
default: ""
38+
type: string
39+
optional:
40+
type: boolean
41+
type: object
42+
x-kubernetes-map-type: atomic
43+
secretRef:
44+
properties:
45+
name:
46+
default: ""
47+
type: string
48+
optional:
49+
type: boolean
50+
type: object
51+
x-kubernetes-map-type: atomic
52+
type: object
53+
type: array
54+
type: object
2955
image:
3056
type: string
3157
imagePullSecrets:

pkg/testrun/plz.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ func NewPLZTestRun(plz *v1alpha1.PrivateLoadZone, token string, trData *cloud.Te
6060
InitContainers: []v1alpha1.InitContainer{
6161
initContainer,
6262
},
63-
Env: envVars,
63+
Env: envVars,
64+
EnvFrom: plz.Spec.Config.ToEnvFromSource(),
6465
},
6566
Starter: v1alpha1.Pod{
6667
ServiceAccountName: plz.Spec.ServiceAccountName,

pkg/testrun/plz_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func Test_NewPLZTestRun(t *testing.T) {
4848
Name: "K6_CLOUD_HOST",
4949
Value: mainIngest,
5050
}},
51+
EnvFrom: []corev1.EnvFromSource{},
5152
},
5253
Script: v1alpha1.K6Script{
5354
LocalFile: "/test/archive.tar",

0 commit comments

Comments
 (0)