Storage class preflight

This commit is contained in:
Marc Campbell
2019-07-17 21:30:01 +00:00
parent 80253a1eb3
commit f693073aaf
8 changed files with 100 additions and 18 deletions

View File

@@ -396,6 +396,8 @@ spec:
properties:
clusterVersion:
properties:
checkName:
type: string
outcomes:
items:
properties:
@@ -433,7 +435,7 @@ spec:
type: object
storageClass:
properties:
name:
checkName:
type: string
outcomes:
items:
@@ -467,9 +469,11 @@ spec:
type: object
type: object
type: array
storageClassName:
type: string
required:
- outcomes
- name
- storageClassName
type: object
type: object
type: array

View File

@@ -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
@@ -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))
@@ -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))

View File

@@ -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

View File

@@ -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")
}

View File

@@ -32,7 +32,7 @@ func analyzeClusterVersion(analyzer *troubleshootv1beta1.ClusterVersion, getColl
message := ""
uri := ""
title := analyzer.Name
title := analyzer.CheckName
if title == "" {
title = "Required Kubernetes Version"
}

View File

@@ -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
}

View File

@@ -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"`
}

View File

@@ -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 {