Skip to content

Commit b30daa2

Browse files
authored
chore: opsdefinition env support optional setting (#9435)
1 parent 265c3d5 commit b30daa2

7 files changed

Lines changed: 32 additions & 0 deletions

File tree

apis/apps/v1alpha1/opsdefinition_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ type OpsEnvVar struct {
158158
//
159159
// +kubebuilder:validation:Required
160160
ValueFrom *OpsVarSource `json:"valueFrom"`
161+
162+
// Specify whether the ENV must be defined.
163+
//
164+
// +optional
165+
Optional *bool `json:"optional,omitempty"`
161166
}
162167

163168
// +kubebuilder:validation:XValidation:rule="has(self.envRef) || has(self.fieldPath)", message="either fieldPath and envRef."

apis/apps/v1alpha1/zz_generated.deepcopy.go

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

config/crd/bases/apps.kubeblocks.io_opsdefinitions.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7688,6 +7688,9 @@ spec:
76887688
Specifies the name of the environment variable to be injected into Pods executing OpsActions.
76897689
It must conform to the C_IDENTIFIER format, which includes only alphanumeric characters and underscores, and cannot begin with a digit.
76907690
type: string
7691+
optional:
7692+
description: Specify whether the ENV must be defined.
7693+
type: boolean
76917694
valueFrom:
76927695
description: Specifies the source of the environment variable's
76937696
value.

controllers/apps/operations/custom/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ func buildEnvVars(reqCtx intctrlutil.RequestCtx,
162162
envVar, err = buildVarWithFieldPath(targetPod, vars[i].ValueFrom.FieldRef.FieldPath)
163163
}
164164
if envVar == nil {
165+
if vars[i].Optional != nil && *vars[i].Optional {
166+
continue
167+
}
165168
return nil, intctrlutil.NewFatalError(fmt.Sprintf(`can not find the env "%s" in the container "%s"`, envVarRef.EnvName, envVarRef.TargetContainerName))
166169
}
167170
envVar.Name = vars[i].Name

deploy/helm/crds/apps.kubeblocks.io_opsdefinitions.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7688,6 +7688,9 @@ spec:
76887688
Specifies the name of the environment variable to be injected into Pods executing OpsActions.
76897689
It must conform to the C_IDENTIFIER format, which includes only alphanumeric characters and underscores, and cannot begin with a digit.
76907690
type: string
7691+
optional:
7692+
description: Specify whether the ENV must be defined.
7693+
type: boolean
76917694
valueFrom:
76927695
description: Specifies the source of the environment variable's
76937696
value.

deploy/helm/templates/opsdefinition.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ spec:
1616
envRef:
1717
envName: KB_POD_IP
1818
- name: SYNCER_SERVICE_PORT
19+
optional: true
1920
valueFrom:
2021
envRef:
2122
envName: SYNCER_SERVICE_PORT

docs/developer_docs/api-reference/cluster.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15194,6 +15194,18 @@ OpsVarSource
1519415194
<p>Specifies the source of the environment variable&rsquo;s value.</p>
1519515195
</td>
1519615196
</tr>
15197+
<tr>
15198+
<td>
15199+
<code>optional</code><br/>
15200+
<em>
15201+
bool
15202+
</em>
15203+
</td>
15204+
<td>
15205+
<em>(Optional)</em>
15206+
<p>Specify whether the ENV must be defined.</p>
15207+
</td>
15208+
</tr>
1519715209
</tbody>
1519815210
</table>
1519915211
<h3 id="apps.kubeblocks.io/v1alpha1.OpsExecAction">OpsExecAction

0 commit comments

Comments
 (0)