Skip to content

Commit 8cabcd9

Browse files
committed
Allow running custom script for debugging purposes
This commit adds a CustomScriptConfigMap spec field to let users run custom scripts for debugging purposes. If CustomScriptConfigMap is used, the status of the instanceha resource would reflect setting status.unsupported.
1 parent c2d4a35 commit 8cabcd9

File tree

6 files changed

+59
-18
lines changed

6 files changed

+59
-18
lines changed

apis/bases/instanceha.openstack.org_instancehas.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ spec:
5656
description: ContainerImage for the InstanceHa container (will be
5757
set to environmental default if empty)
5858
type: string
59+
customScriptConfigMap:
60+
description: |-
61+
CustomScriptConfigMap allows overriding the default instanceha.py script
62+
with a custom script from a pre-created ConfigMap
63+
type: string
5964
fencingSecret:
6065
default: fencing-secret
6166
description: FencingSecret is the name of the Secret containing the
@@ -198,6 +203,10 @@ spec:
198203
podName:
199204
description: PodName
200205
type: string
206+
unsupported:
207+
description: Unsupported - indicates when unsupported configurations
208+
are used
209+
type: string
201210
type: object
202211
type: object
203212
served: true

apis/instanceha/v1beta1/instanceha_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ type InstanceHaSpec struct {
8686
// TopologyRef to apply the Topology defined by the associated CR referenced
8787
// by name
8888
TopologyRef *topologyv1.TopoRef `json:"topologyRef,omitempty"`
89+
90+
// +kubebuilder:validation:Optional
91+
// CustomScriptConfigMap allows overriding the default instanceha.py script
92+
// with a custom script from a pre-created ConfigMap
93+
CustomScriptConfigMap *string `json:"customScriptConfigMap,omitempty"`
8994
}
9095

9196
// InstanceHaStatus defines the observed state of InstanceHa
@@ -104,6 +109,9 @@ type InstanceHaStatus struct {
104109

105110
// LastAppliedTopology - the last applied Topology
106111
LastAppliedTopology *topologyv1.TopoRef `json:"lastAppliedTopology,omitempty"`
112+
113+
// Unsupported - indicates when unsupported configurations are used
114+
Unsupported string `json:"unsupported,omitempty"`
107115
}
108116

109117
//+kubebuilder:object:root=true

apis/instanceha/v1beta1/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/instanceha.openstack.org_instancehas.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ spec:
5656
description: ContainerImage for the InstanceHa container (will be
5757
set to environmental default if empty)
5858
type: string
59+
customScriptConfigMap:
60+
description: |-
61+
CustomScriptConfigMap allows overriding the default instanceha.py script
62+
with a custom script from a pre-created ConfigMap
63+
type: string
5964
fencingSecret:
6065
default: fencing-secret
6166
description: FencingSecret is the name of the Secret containing the
@@ -198,6 +203,10 @@ spec:
198203
podName:
199204
description: PodName
200205
type: string
206+
unsupported:
207+
description: Unsupported - indicates when unsupported configurations
208+
are used
209+
type: string
201210
type: object
202211
type: object
203212
served: true

controllers/instanceha/instanceha_controller.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -367,25 +367,30 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
367367
}
368368

369369
// begin custom script inject
370-
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel("instanceha"), map[string]string{})
371-
envVars := make(map[string]env.Setter)
372-
cms := []util.Template{
373-
// ScriptsConfigMap
374-
{
375-
Name: instance.Name + "-sh",
376-
Namespace: instance.Namespace,
377-
Type: util.TemplateTypeScripts,
378-
InstanceType: instance.Kind,
379-
AdditionalTemplate: map[string]string{},
380-
Labels: cmLabels,
381-
},
382-
}
370+
// Only create the default script ConfigMap if CustomScriptConfigMap is not specified
371+
if instance.Spec.CustomScriptConfigMap == nil || *instance.Spec.CustomScriptConfigMap == "" {
372+
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel("instanceha"), map[string]string{})
373+
envVars := make(map[string]env.Setter)
374+
cms := []util.Template{
375+
// ScriptsConfigMap
376+
{
377+
Name: instance.Name + "-sh",
378+
Namespace: instance.Namespace,
379+
Type: util.TemplateTypeScripts,
380+
InstanceType: instance.Kind,
381+
AdditionalTemplate: map[string]string{},
382+
Labels: cmLabels,
383+
},
384+
}
383385

384-
err = configmap.EnsureConfigMaps(ctx, helper, instance, cms, &envVars)
385-
if err != nil {
386-
return ctrl.Result{}, err
386+
err = configmap.EnsureConfigMaps(ctx, helper, instance, cms, &envVars)
387+
if err != nil {
388+
return ctrl.Result{}, err
389+
}
390+
instance.Status.Unsupported = ""
391+
} else {
392+
instance.Status.Unsupported = "CustomScriptConfigMap"
387393
}
388-
389394
// end custom script inject
390395

391396
// Create netattachment

pkg/instanceha/funcs.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,12 @@ func instancehaPodVolumes(
203203
ConfigMap: &corev1.ConfigMapVolumeSource{
204204
DefaultMode: &config0644AccessMode,
205205
LocalObjectReference: corev1.LocalObjectReference{
206-
Name: instance.Name + "-sh",
206+
Name: func() string {
207+
if instance.Spec.CustomScriptConfigMap != nil && *instance.Spec.CustomScriptConfigMap != "" {
208+
return *instance.Spec.CustomScriptConfigMap
209+
}
210+
return instance.Name + "-sh"
211+
}(),
207212
},
208213
},
209214
},

0 commit comments

Comments
 (0)