@@ -58,6 +58,24 @@ func longhorn(analyzer *troubleshootv1beta2.LonghornAnalyze, getCollectedFileCon
5858 replicas = append (replicas , replica )
5959 }
6060
61+ // get engines.longhorn.io
62+ enginesDir := collect .GetLonghornEnginesDirectory (ns )
63+ enginesGlob := filepath .Join (enginesDir , "*" )
64+ enginesYaml , err := findFiles (enginesGlob )
65+ if err != nil {
66+ return nil , errors .Wrapf (err , "failed to find longhorn engines files under %s" , enginesDir )
67+ }
68+ engines := []* longhornv1beta1.Engine {}
69+ for key , engineYaml := range enginesYaml {
70+ engineYaml = stripRedactedLines (engineYaml )
71+ engine := & longhornv1beta1.Engine {}
72+ err := yaml .Unmarshal (engineYaml , engine )
73+ if err != nil {
74+ return nil , errors .Wrapf (err , "failed to unmarshal engine yaml from %s" , key )
75+ }
76+ engines = append (engines , engine )
77+ }
78+
6179 results := []* AnalyzeResult {}
6280
6381 for _ , node := range nodes {
@@ -68,6 +86,10 @@ func longhorn(analyzer *troubleshootv1beta2.LonghornAnalyze, getCollectedFileCon
6886 results = append (results , analyzeLonghornReplica (replica ))
6987 }
7088
89+ for _ , engine := range engines {
90+ results = append (results , analyzeLonghornEngine (engine ))
91+ }
92+
7193 return results , nil
7294}
7395
@@ -123,17 +145,35 @@ func analyzeLonghornReplica(replica *longhornv1beta1.Replica) *AnalyzeResult {
123145 return result
124146}
125147
148+ func analyzeLonghornEngine (engine * longhornv1beta1.Engine ) * AnalyzeResult {
149+ result := & AnalyzeResult {
150+ Title : fmt .Sprintf ("Longhorn Engine: %s" , engine .Name ),
151+ }
152+
153+ desired := engine .Spec .InstanceSpec .DesireState
154+ actual := engine .Status .InstanceStatus .CurrentState
155+
156+ if desired != actual {
157+ result .IsWarn = true
158+ result .Message = fmt .Sprintf ("Longhorn engine %s current status %q, should be %q" , engine .Name , actual , desired )
159+ return result
160+ }
161+
162+ result .IsPass = true
163+ result .Message = fmt .Sprintf ("Engine is %s" , actual )
164+
165+ return result
166+ }
167+
126168func stripRedactedLines (yaml []byte ) []byte {
127169 buf := bytes .NewBuffer (yaml )
128170 scanner := bufio .NewScanner (buf )
129171
130172 out := []byte {}
131173
132174 for scanner .Scan () {
133- if strings .Contains (scanner .Text (), redact .MASK_TEXT ) {
134- continue
135- }
136- out = append (out , scanner .Bytes ()... )
175+ line := strings .ReplaceAll (scanner .Text (), redact .MASK_TEXT , "HIDDEN" )
176+ out = append (out , []byte (line )... )
137177 out = append (out , '\n' )
138178 }
139179
0 commit comments