Skip to content

Commit c2e865c

Browse files
authored
nit(external-plugins): rename/clarify state plugin is for HealthState (#699)
Signed-off-by: Gyuho Lee <[email protected]> Signed-off-by: Gyuho Lee <[email protected]>
1 parent f5a6223 commit c2e865c

12 files changed

+112
-110
lines changed

client/v1/v1_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ func TestGetCustomPlugins(t *testing.T) {
535535
"test": {
536536
PluginName: "test",
537537
Type: pkgcustomplugins.SpecTypeComponent,
538-
StatePlugin: &pkgcustomplugins.Plugin{
538+
HealthStatePlugin: &pkgcustomplugins.Plugin{
539539
Steps: []pkgcustomplugins.Step{
540540
{
541541
Name: "test-step",
@@ -646,7 +646,7 @@ func TestReadCustomPluginSpecs(t *testing.T) {
646646
"test": {
647647
PluginName: "test",
648648
Type: pkgcustomplugins.SpecTypeComponent,
649-
StatePlugin: &pkgcustomplugins.Plugin{
649+
HealthStatePlugin: &pkgcustomplugins.Plugin{
650650
Steps: []pkgcustomplugins.Step{
651651
{
652652
Name: "test-step",
@@ -729,7 +729,7 @@ func createValidPluginSpec() pkgcustomplugins.Spec {
729729
return pkgcustomplugins.Spec{
730730
PluginName: "test-plugin",
731731
Type: pkgcustomplugins.SpecTypeComponent,
732-
StatePlugin: &pkgcustomplugins.Plugin{
732+
HealthStatePlugin: &pkgcustomplugins.Plugin{
733733
Steps: []pkgcustomplugins.Step{
734734
{
735735
RunBashScript: &pkgcustomplugins.RunBashScript{

e2e/e2e_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ var _ = Describe("[GPUD E2E]", Ordered, func() {
9090
{
9191
PluginName: "init-plugin",
9292
Type: pkgcustomplugins.SpecTypeInit,
93-
StatePlugin: &pkgcustomplugins.Plugin{
93+
HealthStatePlugin: &pkgcustomplugins.Plugin{
9494
Steps: []pkgcustomplugins.Step{
9595
{
9696
Name: "first-step",
@@ -435,7 +435,7 @@ var _ = Describe("[GPUD E2E]", Ordered, func() {
435435
PluginName: pluginName,
436436
Type: pkgcustomplugins.SpecTypeComponent,
437437
DryRun: true,
438-
StatePlugin: &pkgcustomplugins.Plugin{
438+
HealthStatePlugin: &pkgcustomplugins.Plugin{
439439
Steps: []pkgcustomplugins.Step{
440440
{
441441
Name: "first-step",
@@ -489,21 +489,21 @@ var _ = Describe("[GPUD E2E]", Ordered, func() {
489489

490490
testPluginSpec.Interval = metav1.Duration{Duration: time.Minute}
491491
testPluginSpec.DryRun = false
492-
testPluginSpec.StatePlugin.Steps = append(testPluginSpec.StatePlugin.Steps, pkgcustomplugins.Step{
492+
testPluginSpec.HealthStatePlugin.Steps = append(testPluginSpec.HealthStatePlugin.Steps, pkgcustomplugins.Step{
493493
Name: "third-step",
494494
RunBashScript: &pkgcustomplugins.RunBashScript{
495495
Script: "echo 111 > " + fileToWrite,
496496
ContentType: "plaintext",
497497
},
498498
})
499-
testPluginSpec.StatePlugin.Steps = append(testPluginSpec.StatePlugin.Steps, pkgcustomplugins.Step{
499+
testPluginSpec.HealthStatePlugin.Steps = append(testPluginSpec.HealthStatePlugin.Steps, pkgcustomplugins.Step{
500500
Name: "fourth-step",
501501
RunBashScript: &pkgcustomplugins.RunBashScript{
502502
Script: "echo '" + pkgcustomplugins.HealthStateOutputPrefixType + ` Degraded'`,
503503
ContentType: "plaintext",
504504
},
505505
})
506-
testPluginSpec.StatePlugin.Steps = append(testPluginSpec.StatePlugin.Steps, pkgcustomplugins.Step{
506+
testPluginSpec.HealthStatePlugin.Steps = append(testPluginSpec.HealthStatePlugin.Steps, pkgcustomplugins.Step{
507507
Name: "fifth-step",
508508
RunBashScript: &pkgcustomplugins.RunBashScript{
509509
Script: "echo '" + pkgcustomplugins.HealthStateOutputPrefixReason + ` test'`,

pkg/custom-plugins/component.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (c *component) Check() components.CheckResult {
102102
c.lastMu.Unlock()
103103
}()
104104

105-
if c.spec.StatePlugin == nil {
105+
if c.spec.HealthStatePlugin == nil {
106106
cr.health = apiv1.HealthStateTypeHealthy
107107
cr.reason = "no state plugin defined"
108108
return cr
@@ -111,7 +111,7 @@ func (c *component) Check() components.CheckResult {
111111
cctx, ccancel := context.WithTimeout(c.ctx, c.spec.Timeout.Duration)
112112
defer ccancel()
113113

114-
cr.out, cr.exitCode, cr.err = c.spec.StatePlugin.executeAllSteps(cctx)
114+
cr.out, cr.exitCode, cr.err = c.spec.HealthStatePlugin.executeAllSteps(cctx)
115115
cr.output = string(cr.out)
116116

117117
if cr.err != nil {

pkg/custom-plugins/component_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func TestComponent_Check_WithStatePlugin(t *testing.T) {
280280
Timeout: metav1.Duration{
281281
Duration: time.Second * 10,
282282
},
283-
StatePlugin: statePlugin,
283+
HealthStatePlugin: statePlugin,
284284
}
285285

286286
c := &component{
@@ -334,7 +334,7 @@ func TestComponent_Check_WithFailingStatePlugin(t *testing.T) {
334334
Timeout: metav1.Duration{
335335
Duration: time.Second * 10,
336336
},
337-
StatePlugin: statePlugin,
337+
HealthStatePlugin: statePlugin,
338338
}
339339

340340
c := &component{
@@ -386,7 +386,7 @@ func TestComponent_Check_WithTimeoutContext(t *testing.T) {
386386
Timeout: metav1.Duration{
387387
Duration: time.Second * 10, // This will be overridden by the context timeout
388388
},
389-
StatePlugin: statePlugin,
389+
HealthStatePlugin: statePlugin,
390390
}
391391

392392
c := &component{
@@ -678,8 +678,8 @@ func TestComponent_CheckWithOutput(t *testing.T) {
678678
}
679679

680680
spec := &Spec{
681-
PluginName: "test-plugin",
682-
StatePlugin: statePlugin,
681+
PluginName: "test-plugin",
682+
HealthStatePlugin: statePlugin,
683683
Timeout: metav1.Duration{
684684
Duration: time.Second * 10,
685685
},
@@ -775,7 +775,7 @@ func TestComponent_Check_SuccessfulPlugin(t *testing.T) {
775775
Timeout: metav1.Duration{
776776
Duration: time.Second * 10,
777777
},
778-
StatePlugin: statePlugin,
778+
HealthStatePlugin: statePlugin,
779779
}
780780

781781
c := &component{

pkg/custom-plugins/testdata/plugins.base64.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
- plugin_name: "nvidia-smi"
22
type: component
33

4-
state_plugin:
4+
health_state_plugin:
55
steps:
66
- name: "Run nvidia-smi"
77
run_bash_script:

pkg/custom-plugins/testdata/plugins.plaintext.0.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
- plugin_name: test plugin 1
22
type: component
33

4-
state_plugin:
4+
health_state_plugin:
55
steps:
66
- name: "Install Python"
77
run_bash_script:
@@ -23,7 +23,7 @@
2323
- plugin_name: test plugin 2
2424
type: component
2525

26-
state_plugin:
26+
health_state_plugin:
2727
steps:
2828
- name: "Install Python"
2929
run_bash_script:

pkg/custom-plugins/testdata/plugins.plaintext.1.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- plugin_name: nv-plugin-install-python
44
type: init
55

6-
state_plugin:
6+
health_state_plugin:
77
steps:
88
- name: Install Python
99
run_bash_script:
@@ -42,7 +42,7 @@
4242
- plugin_name: nv-plugin-fail-me
4343
type: component
4444

45-
state_plugin:
45+
health_state_plugin:
4646
steps:
4747
- name: Exit 1
4848
run_bash_script:
@@ -66,7 +66,7 @@
6666
- plugin_name: nv-plugin-simple-script-gpu-throttle
6767
type: component
6868

69-
state_plugin:
69+
health_state_plugin:
7070
steps:
7171
- name: Run health check
7272
run_bash_script:
@@ -139,7 +139,7 @@
139139
- plugin_name: nv-plugin-simple-script-gpu-power-state
140140
type: component
141141

142-
state_plugin:
142+
health_state_plugin:
143143
steps:
144144
- name: Run health check
145145
run_bash_script:

pkg/custom-plugins/type_plugin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestPluginValidate(t *testing.T) {
1414
plugin := Spec{
1515
PluginName: "test",
1616
Type: SpecTypeComponent,
17-
StatePlugin: &Plugin{
17+
HealthStatePlugin: &Plugin{
1818
Steps: []Step{
1919
{
2020
Name: "test",

pkg/custom-plugins/type_run_bash_script_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestDecodeWithInvalidBase64(t *testing.T) {
7676
// Create a plugin with invalid base64 encoded scripts
7777
plugin := Spec{
7878
Type: SpecTypeComponent,
79-
StatePlugin: &Plugin{
79+
HealthStatePlugin: &Plugin{
8080
Steps: []Step{
8181
{
8282
Name: "test-plugin",
@@ -93,7 +93,7 @@ func TestDecodeWithInvalidBase64(t *testing.T) {
9393
err := plugin.Validate()
9494
assert.Error(t, err)
9595

96-
_, err = plugin.StatePlugin.Steps[0].RunBashScript.decode()
96+
_, err = plugin.HealthStatePlugin.Steps[0].RunBashScript.decode()
9797
assert.Error(t, err)
9898
}
9999

@@ -102,7 +102,7 @@ func TestDecodeWithPlaintext(t *testing.T) {
102102
plugin := Spec{
103103
PluginName: "test-plaintext",
104104
Type: SpecTypeComponent,
105-
StatePlugin: &Plugin{
105+
HealthStatePlugin: &Plugin{
106106
Steps: []Step{
107107
{
108108
Name: "test-plaintext",
@@ -121,7 +121,7 @@ func TestDecodeWithPlaintext(t *testing.T) {
121121
assert.NoError(t, err)
122122

123123
// Test decoding the plaintext scripts
124-
stateScript, err := plugin.StatePlugin.Steps[0].RunBashScript.decode()
124+
stateScript, err := plugin.HealthStatePlugin.Steps[0].RunBashScript.decode()
125125
assert.NoError(t, err)
126126
assert.Equal(t, "echo 'Hello, World!'", stateScript)
127127
}

pkg/custom-plugins/type_spec.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ func (spec *Spec) Validate() error {
7878
return ErrComponentNameRequired
7979
}
8080

81-
if spec.StatePlugin == nil {
81+
if spec.HealthStatePlugin == nil {
8282
return ErrMissingStatePlugin
8383
}
84-
if err := spec.StatePlugin.Validate(); err != nil {
84+
if err := spec.HealthStatePlugin.Validate(); err != nil {
8585
return err
8686
}
8787

@@ -103,10 +103,10 @@ func (spec *Spec) ComponentName() string {
103103

104104
// RunStatePlugin runs the state plugin and returns the output and its exit code.
105105
func (spec *Spec) RunStatePlugin(ctx context.Context) ([]byte, int32, error) {
106-
if spec.StatePlugin == nil {
106+
if spec.HealthStatePlugin == nil {
107107
return nil, 0, ErrMissingStatePlugin
108108
}
109-
if err := spec.StatePlugin.Validate(); err != nil {
109+
if err := spec.HealthStatePlugin.Validate(); err != nil {
110110
return nil, 0, err
111111
}
112112
if spec.DryRun {
@@ -115,5 +115,5 @@ func (spec *Spec) RunStatePlugin(ctx context.Context) ([]byte, int32, error) {
115115

116116
cctx, cancel := context.WithTimeout(ctx, spec.Timeout.Duration)
117117
defer cancel()
118-
return spec.StatePlugin.executeAllSteps(cctx)
118+
return spec.HealthStatePlugin.executeAllSteps(cctx)
119119
}

0 commit comments

Comments
 (0)