Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions config/crds/troubleshoot.replicated.com_preflights.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,51 @@ spec:
- outcomes
- customResourceDefinitionName
type: object
ingress:
properties:
checkName:
type: string
ingressName:
type: string
namespace:
type: string
outcomes:
items:
properties:
fail:
properties:
message:
type: string
uri:
type: string
when:
type: string
type: object
pass:
properties:
message:
type: string
uri:
type: string
when:
type: string
type: object
warn:
properties:
message:
type: string
uri:
type: string
when:
type: string
type: object
type: object
type: array
required:
- outcomes
- ingressName
- namespace
type: object
storageClass:
properties:
checkName:
Expand Down
32 changes: 32 additions & 0 deletions config/crds/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func (in *Analyze) DeepCopyInto(out *Analyze) {
*out = new(CustomResourceDefinition)
(*in).DeepCopyInto(*out)
}
if in.Ingress != nil {
in, out := &in.Ingress, &out.Ingress
*out = new(Ingress)
(*in).DeepCopyInto(*out)
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Analyze.
Expand Down Expand Up @@ -544,6 +549,33 @@ func (in *CustomResourceDefinition) DeepCopy() *CustomResourceDefinition {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Ingress) DeepCopyInto(out *Ingress) {
*out = *in
out.AnalyzeMeta = in.AnalyzeMeta
if in.Outcomes != nil {
in, out := &in.Outcomes, &out.Outcomes
*out = make([]*Outcome, len(*in))
for i := range *in {
if (*in)[i] != nil {
in, out := &(*in)[i], &(*out)[i]
*out = new(Outcome)
(*in).DeepCopyInto(*out)
}
}
}
}

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

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Outcome) DeepCopyInto(out *Outcome) {
*out = *in
Expand Down
15 changes: 8 additions & 7 deletions config/samples/troubleshoot_v1beta1_preflight.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ spec:
# message: The top secret secret is missing
# pass:
# message: You know the secret
# - ingress:
# namespace: default
# name: connect-to-me
# fail:
# message: The ingress isn't ingressing
# pass:
# message: All systems ok on ingress
- ingress:
namespace: default
ingressName: connect-to-me
outcomes:
- fail:
message: The ingress isn't ingressing
- pass:
message: All systems ok on ingress
# - imagePullSecret:
# name: replicated
# namespace: my-app
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b h1:aBGgKJUM9Hk/3AE8WaZIApnTxG35kbu
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
k8s.io/api v0.0.0-20190703205437-39734b2a72fe h1:MFaHtAyhZcfBZocN91muHSqnwiF5yfXx7yGoehneNYg=
k8s.io/api v0.0.0-20190703205437-39734b2a72fe/go.mod h1:J5EZ0KSEjvyKOBy5BDHSF3zn82madLLWg7nUKaOHZKU=
k8s.io/api v0.0.0-20190717022910-653c86b0609b h1:WiE134uexhvhHw4DjJuYsghv792UCe2xN5SHQOayf28=
k8s.io/apiextensions-apiserver v0.0.0-20190228180357-d002e88f6236 h1:JfFtjaElBIgYKCWEtYQkcNrTpW+lMO4GJy8NP6SVQmM=
k8s.io/apiextensions-apiserver v0.0.0-20190228180357-d002e88f6236/go.mod h1:IxkesAMoaCRoLrPJdZNZUQp9NfZnzqaVzLhb2VEQzXE=
k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8 h1:q1Qvjzs/iEdXF6A1a8H3AKVFDzJNcJn3nXMs6R6qFtA=
Expand Down
3 changes: 3 additions & 0 deletions pkg/analyze/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getCollectedFileContents fun
if analyzer.CustomResourceDefinition != nil {
return analyzeCustomResourceDefinition(analyzer.CustomResourceDefinition, getCollectedFileContents)
}
if analyzer.Ingress != nil {
return analyzeIngress(analyzer.Ingress, getCollectedFileContents)
}

return nil, errors.New("invalid analyzer")
}
54 changes: 54 additions & 0 deletions pkg/analyze/ingress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package analyzer

import (
"encoding/json"
"fmt"

troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
)

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

var ingresses []extensionsv1beta1.Ingress
if err := json.Unmarshal(ingressData, &ingresses); err != nil {
return nil, err
}

title := analyzer.CheckName
if title == "" {
title = fmt.Sprintf("Ingress %s", analyzer.IngressName)
}

result := AnalyzeResult{
Title: title,
}

for _, ingress := range ingresses {
if ingress.Name == analyzer.IngressName {
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
}
8 changes: 8 additions & 0 deletions pkg/apis/troubleshoot/v1beta1/analyzer_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ type CustomResourceDefinition struct {
CustomResourceDefinitionName string `json:"customResourceDefinitionName" yaml:"customResourceDefinitionName"`
}

type Ingress struct {
AnalyzeMeta `json:",inline" yaml:",inline"`
Outcomes []*Outcome `json:"outcomes" yaml:"outcomes"`
IngressName string `json:"ingressName" yaml:"ingressName"`
Namespace string `json:"namespace" yaml:"namespace"`
}

type AnalyzeMeta struct {
CheckName string `json:"checkName,omitempty" yaml:"checkName,omitempty"`
}
Expand All @@ -37,4 +44,5 @@ type Analyze struct {
ClusterVersion *ClusterVersion `json:"clusterVersion,omitempty" yaml:"clusterVersion,omitempty"`
StorageClass *StorageClass `json:"storageClass,omitempty" yaml:"storageClass,omitempty"`
CustomResourceDefinition *CustomResourceDefinition `json:"customResourceDefinition,omitempty" yaml:"customResourceDefinition,omitempty"`
Ingress *Ingress `json:"ingress,omitempty" yaml:"ingress,omitempty"`
}
32 changes: 32 additions & 0 deletions pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func (in *Analyze) DeepCopyInto(out *Analyze) {
*out = new(CustomResourceDefinition)
(*in).DeepCopyInto(*out)
}
if in.Ingress != nil {
in, out := &in.Ingress, &out.Ingress
*out = new(Ingress)
(*in).DeepCopyInto(*out)
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Analyze.
Expand Down Expand Up @@ -560,6 +565,33 @@ func (in *CustomResourceDefinition) DeepCopy() *CustomResourceDefinition {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Ingress) DeepCopyInto(out *Ingress) {
*out = *in
out.AnalyzeMeta = in.AnalyzeMeta
if in.Outcomes != nil {
in, out := &in.Outcomes, &out.Outcomes
*out = make([]*Outcome, len(*in))
for i := range *in {
if (*in)[i] != nil {
in, out := &(*in)[i], &(*out)[i]
*out = new(Outcome)
(*in).DeepCopyInto(*out)
}
}
}
}

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

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