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
@@ -14,9 +19,6 @@ func getCoreMicroShiftWorkloads() (map[string]NamespaceWorkloads, error) {
14
19
}
15
20
16
21
workloads := map [string ]NamespaceWorkloads {
17
- "openshift-ovn-kubernetes" : {
18
- DaemonSets : []string {"ovnkube-master" , "ovnkube-node" },
19
- },
20
22
"openshift-service-ca" : {
21
23
Deployments : []string {"service-ca" },
22
24
},
@@ -30,15 +32,82 @@ func getCoreMicroShiftWorkloads() (map[string]NamespaceWorkloads, error) {
30
32
},
31
33
},
32
34
}
33
- fillOptionalWorkloadsIfApplicable (cfg , workloads )
35
+ if cfg .Network .IsEnabled () {
36
+ workloads ["openshift-ovn-kubernetes" ] = NamespaceWorkloads {
37
+ DaemonSets : []string {"ovnkube-master" , "ovnkube-node" },
38
+ }
39
+ }
40
+ if err := fillOptionalWorkloadsIfApplicable (cfg , workloads ); err != nil {
41
+ return nil , err
42
+ }
34
43
35
44
return workloads , nil
36
45
}
37
46
38
- func fillOptionalWorkloadsIfApplicable (cfg * config.Config , workloads map [string ]NamespaceWorkloads ) {
39
- klog .V (2 ).Infof ("Configured storage driver value: %q" , string (cfg .Storage .Driver ))
40
- if cfg .Storage .IsEnabled () {
41
- 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 {
42
111
workloads ["openshift-storage" ] = NamespaceWorkloads {
43
112
DaemonSets : []string {"vg-manager" },
44
113
Deployments : []string {"lvms-operator" },
@@ -50,6 +119,7 @@ func fillOptionalWorkloadsIfApplicable(cfg *config.Config, workloads map[string]
50
119
Deployments : comps ,
51
120
}
52
121
}
122
+ return nil
53
123
}
54
124
55
125
func getExpectedCSIComponents (cfg * config.Config ) []string {
0 commit comments