Skip to content

Commit

Permalink
Storage class preflight
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Jul 17, 2019
1 parent 80253a1 commit f693073
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 18 deletions.
8 changes: 6 additions & 2 deletions config/crds/troubleshoot.replicated.com_preflights.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ spec:
properties:
clusterVersion:
properties:
checkName:
type: string
outcomes:
items:
properties:
Expand Down Expand Up @@ -433,7 +435,7 @@ spec:
type: object
storageClass:
properties:
name:
checkName:
type: string
outcomes:
items:
Expand Down Expand Up @@ -467,9 +469,11 @@ spec:
type: object
type: object
type: array
storageClassName:
type: string
required:
- outcomes
- name
- storageClassName
type: object
type: object
type: array
Expand Down
17 changes: 17 additions & 0 deletions config/crds/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ func (in *Analyze) DeepCopy() *Analyze {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *AnalyzeMeta) DeepCopyInto(out *AnalyzeMeta) {
*out = *in
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AnalyzeMeta.
func (in *AnalyzeMeta) DeepCopy() *AnalyzeMeta {
if in == nil {
return nil
}
out := new(AnalyzeMeta)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Analyzer) DeepCopyInto(out *Analyzer) {
*out = *in
Expand Down Expand Up @@ -244,6 +259,7 @@ func (in *ClusterResources) DeepCopy() *ClusterResources {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterVersion) DeepCopyInto(out *ClusterVersion) {
*out = *in
out.AnalyzeMeta = in.AnalyzeMeta
if in.Outcomes != nil {
in, out := &in.Outcomes, &out.Outcomes
*out = make([]*Outcome, len(*in))
Expand Down Expand Up @@ -790,6 +806,7 @@ func (in *SingleOutcome) DeepCopy() *SingleOutcome {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StorageClass) DeepCopyInto(out *StorageClass) {
*out = *in
out.AnalyzeMeta = in.AnalyzeMeta
if in.Outcome != nil {
in, out := &in.Outcome, &out.Outcome
*out = make([]*Outcome, len(*in))
Expand Down
17 changes: 10 additions & 7 deletions config/samples/troubleshoot_v1beta1_preflight.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ spec:
- fail:
when: "< 1.14.0"
message: You need more kubernetes
uri:
uri: https://help.replicated.com/kubernetes-version
- warn:
when: "< 1.15.0"
message: You have barely enough kubernetes
uri: https://help.replicated.com/kubernetes-version
- pass:
message: Good job keeping k8s current
# - storageClass:
# name: "my-custom-storage-class"
# fail:
# message: The custom storage class thing was not found
# pass:
# message: All good on storage classes
- storageClass:
checkName: Required storage classes
storageClassName: "microk8s-hostpath"
outcomes:
- fail:
message: The micr0k8s storage class thing was not found
- pass:
message: All good on storage classes
# - manifests:
# - secret:
# namespace: default
Expand Down
5 changes: 4 additions & 1 deletion pkg/analyze/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getCollectedFileContents fun
if analyzer.ClusterVersion != nil {
return analyzeClusterVersion(analyzer.ClusterVersion, getCollectedFileContents)
}
if analyzer.StorageClass != nil {
return analyzeStorageClass(analyzer.StorageClass, getCollectedFileContents)
}

return nil, errors.New("invalid analyer")
return nil, errors.New("invalid analyzer")
}
2 changes: 1 addition & 1 deletion pkg/analyze/cluster_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func analyzeClusterVersion(analyzer *troubleshootv1beta1.ClusterVersion, getColl
message := ""
uri := ""

title := analyzer.Name
title := analyzer.CheckName
if title == "" {
title = "Required Kubernetes Version"
}
Expand Down
55 changes: 55 additions & 0 deletions pkg/analyze/storage_class.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package analyzer

import (
"encoding/json"
"fmt"

troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
storagev1beta1 "k8s.io/api/storage/v1beta1"
// "github.com/replicatedhq/troubleshoot/pkg/collect"
)

func analyzeStorageClass(analyzer *troubleshootv1beta1.StorageClass, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
storageClassesData, err := getCollectedFileContents("cluster-resources/storage-classes.json")
if err != nil {
return nil, err
}

var storageClasses []storagev1beta1.StorageClass
if err := json.Unmarshal(storageClassesData, &storageClasses); err != nil {
return nil, err
}

title := analyzer.CheckName
if title == "" {
title = fmt.Sprintf("Storage class %s", analyzer.StorageClassName)
}

result := AnalyzeResult{
Title: title,
}

for _, storageClass := range storageClasses {
if storageClass.Name == analyzer.StorageClassName {
result.IsPass = true
for _, outcome := range analyzer.Outcomes {
if outcome.Pass != nil {
result.Message = outcome.Pass.Message
result.URI = outcome.Pass.URI
}
}

return &result, nil
}
}

result.IsFail = true
for _, outcome := range analyzer.Outcomes {
if outcome.Fail != nil {
result.Message = outcome.Fail.Message
result.URI = outcome.Fail.URI
}
}

return &result, nil
}
10 changes: 5 additions & 5 deletions pkg/apis/troubleshoot/v1beta1/analyzer_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ type ClusterVersion struct {
}

type StorageClass struct {
AnalyzeMeta `json:",inline" yaml:",inline"`
Outcome []*Outcome `json:"outcomes" yaml:"outcomes"`
Name string `json:"name" yaml:"name"`
AnalyzeMeta `json:",inline" yaml:",inline"`
Outcomes []*Outcome `json:"outcomes" yaml:"outcomes"`
StorageClassName string `json:"storageClassName" yaml:"storageClassName"`
}

type AnalyzeMeta struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
CheckName string `json:"checkName,omitempty" yaml:"checkName,omitempty"`
}

type Analyze struct {
ClusterVersion *ClusterVersion `json:"clusterVersion,omitempty" yaml:"clusterVersion,omitempty"`
StorageClass *StorageClass `json:"storageClass,omitempty" yaml:"supportBundle,omitempty"`
StorageClass *StorageClass `json:"storageClass,omitempty" yaml:"storageClass,omitempty"`
}
4 changes: 2 additions & 2 deletions pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,8 @@ func (in *SingleOutcome) DeepCopy() *SingleOutcome {
func (in *StorageClass) DeepCopyInto(out *StorageClass) {
*out = *in
out.AnalyzeMeta = in.AnalyzeMeta
if in.Outcome != nil {
in, out := &in.Outcome, &out.Outcome
if in.Outcomes != nil {
in, out := &in.Outcomes, &out.Outcomes
*out = make([]*Outcome, len(*in))
for i := range *in {
if (*in)[i] != nil {
Expand Down

0 comments on commit f693073

Please sign in to comment.