1
1
package healthcheck
2
2
3
3
import (
4
+ "bytes"
5
+ "encoding/json"
6
+ "os/exec"
7
+
4
8
"github.com/openshift/microshift/pkg/config"
9
+ "github.com/openshift/microshift/pkg/util"
5
10
"k8s.io/klog/v2"
6
11
)
7
12
@@ -27,20 +32,82 @@ func getCoreMicroShiftWorkloads() (map[string]NamespaceWorkloads, error) {
27
32
},
28
33
},
29
34
}
30
- fillOptionalWorkloadsIfApplicable (cfg , workloads )
31
35
if cfg .Network .IsEnabled () {
32
36
workloads ["openshift-ovn-kubernetes" ] = NamespaceWorkloads {
33
37
DaemonSets : []string {"ovnkube-master" , "ovnkube-node" },
34
38
}
35
39
}
40
+ if err := fillOptionalWorkloadsIfApplicable (cfg , workloads ); err != nil {
41
+ return nil , err
42
+ }
36
43
37
44
return workloads , nil
38
45
}
39
46
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 {
44
111
workloads ["openshift-storage" ] = NamespaceWorkloads {
45
112
DaemonSets : []string {"vg-manager" },
46
113
Deployments : []string {"lvms-operator" },
@@ -52,6 +119,7 @@ func fillOptionalWorkloadsIfApplicable(cfg *config.Config, workloads map[string]
52
119
Deployments : comps ,
53
120
}
54
121
}
122
+ return nil
55
123
}
56
124
57
125
func getExpectedCSIComponents (cfg * config.Config ) []string {
0 commit comments