Skip to content

Commit 903cf45

Browse files
committed
Extended the decision of LVMS expectancy
1 parent 3425bac commit 903cf45

File tree

1 file changed

+73
-5
lines changed

1 file changed

+73
-5
lines changed

pkg/healthcheck/microshift_core_workloads.go

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package healthcheck
22

33
import (
4+
"bytes"
5+
"encoding/json"
6+
"os/exec"
7+
48
"github.com/openshift/microshift/pkg/config"
9+
"github.com/openshift/microshift/pkg/util"
510
"k8s.io/klog/v2"
611
)
712

@@ -27,20 +32,82 @@ func getCoreMicroShiftWorkloads() (map[string]NamespaceWorkloads, error) {
2732
},
2833
},
2934
}
30-
fillOptionalWorkloadsIfApplicable(cfg, workloads)
3135
if cfg.Network.IsEnabled() {
3236
workloads["openshift-ovn-kubernetes"] = NamespaceWorkloads{
3337
DaemonSets: []string{"ovnkube-master", "ovnkube-node"},
3438
}
3539
}
40+
if err := fillOptionalWorkloadsIfApplicable(cfg, workloads); err != nil {
41+
return nil, err
42+
}
3643

3744
return workloads, nil
3845
}
3946

40-
func fillOptionalWorkloadsIfApplicable(cfg *config.Config, workloads map[string]NamespaceWorkloads) {
41-
klog.V(2).Infof("Configured storage driver value: %q", string(cfg.Storage.Driver))
42-
if cfg.Storage.IsEnabled() {
43-
klog.Infof("LVMS is enabled")
47+
func lvmsIsExpected(cfg *config.Config) (bool, error) {
48+
cfgFile := "/etc/microshift/lvmd.yaml"
49+
if exists, err := util.PathExists(cfgFile); err != nil {
50+
return false, err
51+
} else if exists {
52+
klog.Infof("%s exists - expecting LVMS to be deployed", cfgFile)
53+
return true, nil
54+
}
55+
56+
if !cfg.Storage.IsEnabled() {
57+
klog.Infof("LVMS is disabled via config. Configured value: %q", string(cfg.Storage.Driver))
58+
return false, nil
59+
}
60+
61+
cmd := exec.Command("vgs", "--readonly", "--options=name", "--reportformat=json")
62+
output, err := cmd.Output()
63+
if err != nil {
64+
return false, err
65+
}
66+
out := &bytes.Buffer{}
67+
err = json.Compact(out, output)
68+
if err != nil {
69+
klog.Errorf("Failed to compact 'vgs' output: %s", string(output))
70+
} else {
71+
klog.V(2).Infof("vgs reported: %s", out.String())
72+
}
73+
74+
report := struct {
75+
Report []struct {
76+
VGs []struct {
77+
VGName string `json:"vg_name"`
78+
} `json:"vg"`
79+
} `json:"report"`
80+
}{}
81+
82+
err = json.Unmarshal(output, &report)
83+
if err != nil {
84+
return false, err
85+
}
86+
87+
if len(report.Report) == 0 || len(report.Report[0].VGs) == 0 {
88+
klog.Infof("Detected 0 volume groups - LVMS is not expected")
89+
return false, nil
90+
}
91+
92+
if len(report.Report[0].VGs) == 1 {
93+
klog.Infof("Detected 1 volume group (%s) - LVMS is expected", report.Report[0].VGs[0].VGName)
94+
return true, nil
95+
}
96+
97+
for _, vg := range report.Report[0].VGs {
98+
if vg.VGName == "microshift" {
99+
klog.Infof("Found volume group named 'microshift' - LVMS is expected")
100+
return true, nil
101+
}
102+
}
103+
104+
return false, nil
105+
}
106+
107+
func fillOptionalWorkloadsIfApplicable(cfg *config.Config, workloads map[string]NamespaceWorkloads) error {
108+
if expected, err := lvmsIsExpected(cfg); err != nil {
109+
return err
110+
} else if expected {
44111
workloads["openshift-storage"] = NamespaceWorkloads{
45112
DaemonSets: []string{"vg-manager"},
46113
Deployments: []string{"lvms-operator"},
@@ -52,6 +119,7 @@ func fillOptionalWorkloadsIfApplicable(cfg *config.Config, workloads map[string]
52119
Deployments: comps,
53120
}
54121
}
122+
return nil
55123
}
56124

57125
func getExpectedCSIComponents(cfg *config.Config) []string {

0 commit comments

Comments
 (0)