Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbelu committed Dec 18, 2024
1 parent a7daf9b commit 7a15aeb
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 26 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/temporalcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ type DeploymentOverride struct {
// Specification of the desired behavior of the Deployment.
// +optional
Spec *DeploymentOverrideSpec `json:"spec,omitempty"`
JsonPatch *apiextensionsv1.JSON `json:"jsonPatch,omitempty"`
JSONPatch *apiextensionsv1.JSON `json:"jsonPatch,omitempty"`
}

// DeploymentOverrideSpec provides the ability to override a Deployment Spec.
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 38 additions & 13 deletions docs/features/overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ The API provides you the ability to apply your overrides:
- per temporal service (using `spec.services.[frontend|history|matching|worker].overrides`)
- for all services (using `spec.services.overrides`)

There are two ways of performing overrides, one is via StrategicPatchMerge and one using RFC6902 JSON patches. You can find examples of both below. If working with certain fields that aren't handled by StrategicPatchMerge properly (i.e., arrays that don't have go struct tags for merging valid for your use case), you may want to consider using JSON patches.

## Overrides for all services

Here is a general example:
Expand Down Expand Up @@ -210,7 +212,7 @@ spec:
value: example.com
```
### Example: mount an extra volume to the frontend pod
### Example: Mount an extra secret volume to the frontend pod
```yaml
apiVersion: temporal.io/v1beta1
Expand All @@ -223,18 +225,18 @@ spec:
frontend:
overrides:
deployment:
spec:
template:
spec:
containers:
- name: service
volumeMounts:
- name: extra-volume
mountPath: /etc/extra
volumes:
- name: extra-volume
configMap:
name: extra-config
jsonPatch:
- op: add
path: /spec/template/spec/containers/0/volumeMounts/-
value:
name: extra-volume
mountPath: /etc/extra
- op: add
path: /spec/template/spec/volumes/-
value:
name: extra-volume
secret:
secretName: test-secret
```
### Example: Add an environment variable from secretRef to the frontend pod
Expand Down Expand Up @@ -286,6 +288,29 @@ spec:
service: frontend.temporal.temporal.svc.cluster.local
```
### Example: Add environment variable from a secret to frontend pod
```yaml
apiVersion: temporal.io/v1beta1
kind: TemporalCluster
metadata:
name: prod
spec:
# [...]
services:
frontend:
overrides:
deployment:
jsonPatch:
- op: add
path: /spec/template/spec/containers/0/env/-
value:
name: TEST
valueFrom:
secretKeyRef:
name: test-secret
key: test
```
Read more in [Strategic Merge Patch](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md#strategic-merge-patch).
## Override UI deployment
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubernetes/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func ApplyDeploymentOverrides(deployment *appsv1.Deployment, override *v1beta1.D
}
}

if override.JsonPatch != nil {
patch, err := jsonpatch.DecodePatch(override.JsonPatch.Raw)
if override.JSONPatch != nil {
patch, err := jsonpatch.DecodePatch(override.JSONPatch.Raw)
if err != nil {
return fmt.Errorf("can't decode json patch: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubernetes/overrides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func TestApplyDeploymentOverrides(t *testing.T) {
},
},
override: &v1beta1.DeploymentOverride{
JsonPatch: &apiextensionsv1.JSON{
JSONPatch: &apiextensionsv1.JSON{
Raw: []byte(`[{"op":"add", "path":"/spec/template/spec/containers/0/env/-", "value":{"name":"b","value":"c"}}]`),
},
},
Expand Down Expand Up @@ -442,7 +442,7 @@ func TestApplyDeploymentOverrides(t *testing.T) {
},
},
override: &v1beta1.DeploymentOverride{
JsonPatch: &apiextensionsv1.JSON{
JSONPatch: &apiextensionsv1.JSON{
Raw: []byte(`[
{"op": "add", "path": "/spec/template/spec/containers/0/volumeMounts/-", "value": {"name": "b", "readOnly": true, "mountPath": "/b"}},
{"op": "add", "path": "/spec/template/spec/volumes/-", "value": {"name": "b", "secret": {"secretName": "test"}}}
Expand Down
8 changes: 4 additions & 4 deletions webhooks/temporalcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,11 @@ func (w *TemporalClusterWebhook) validateCluster(cluster *v1beta1.TemporalCluste

if cluster.Spec.Services != nil {
overrides := cluster.Spec.Services.Overrides
if overrides != nil && overrides.Deployment != nil && overrides.Deployment.Spec != nil && overrides.Deployment.JsonPatch != nil {
if overrides != nil && overrides.Deployment != nil && overrides.Deployment.Spec != nil && overrides.Deployment.JSONPatch != nil {
errs = append(errs,
field.Forbidden(
field.NewPath("spec", "services", "overrides", "deployment", "jsonPatch"),
fmt.Sprintf("Can't set JsonPatch when Spec is set on Deployment override"),
"Can't set JSONPatch when Spec is set on Deployment override",
),
)
}
Expand All @@ -348,11 +348,11 @@ func (w *TemporalClusterWebhook) validateCluster(cluster *v1beta1.TemporalCluste
),
)
}
if spec != nil && spec.Overrides != nil && spec.Overrides.Deployment != nil && spec.Overrides.Deployment.Spec != nil && spec.Overrides.Deployment.JsonPatch != nil {
if spec != nil && spec.Overrides != nil && spec.Overrides.Deployment != nil && spec.Overrides.Deployment.Spec != nil && spec.Overrides.Deployment.JSONPatch != nil {
errs = append(errs,
field.Forbidden(
field.NewPath("spec", "services", string(service), "overrides", "deployment", "jsonPatch"),
fmt.Sprintf("Can't set JsonPatch when Spec is set on Deployment override"),
"Can't set JSONPatch when Spec is set on Deployment override",
),
)
}
Expand Down
4 changes: 2 additions & 2 deletions webhooks/temporalcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func TestValidateCreate(t *testing.T) {
Services: &v1beta1.ServicesSpec{
Overrides: &v1beta1.ServiceSpecOverride{
Deployment: &v1beta1.DeploymentOverride{
JsonPatch: &apiextensionsv1.JSON{
JSONPatch: &apiextensionsv1.JSON{
Raw: []byte(`{ "op": "replace", "path": "/spec/replicas", "value": 3 }`),
},
Spec: &v1beta1.DeploymentOverrideSpec{
Expand All @@ -334,7 +334,7 @@ func TestValidateCreate(t *testing.T) {
PrometheusOperator: false,
},
},
expectedErr: "Forbidden: Can't set JsonPatch when Spec is set on Deployment override",
expectedErr: "Forbidden: Can't set JSONPatch when Spec is set on Deployment override",
},
}

Expand Down

0 comments on commit 7a15aeb

Please sign in to comment.