Skip to content

Commit 524576b

Browse files
marccampbelldivolgin
authored andcommitted
Merge pull request #7 from replicatedhq/preflight
Ingress preflight
2 parents cc8bf57 + e7174ac commit 524576b

File tree

8 files changed

+183
-7
lines changed

8 files changed

+183
-7
lines changed

config/crds/troubleshoot.replicated.com_preflights.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,51 @@ spec:
475475
- outcomes
476476
- customResourceDefinitionName
477477
type: object
478+
ingress:
479+
properties:
480+
checkName:
481+
type: string
482+
ingressName:
483+
type: string
484+
namespace:
485+
type: string
486+
outcomes:
487+
items:
488+
properties:
489+
fail:
490+
properties:
491+
message:
492+
type: string
493+
uri:
494+
type: string
495+
when:
496+
type: string
497+
type: object
498+
pass:
499+
properties:
500+
message:
501+
type: string
502+
uri:
503+
type: string
504+
when:
505+
type: string
506+
type: object
507+
warn:
508+
properties:
509+
message:
510+
type: string
511+
uri:
512+
type: string
513+
when:
514+
type: string
515+
type: object
516+
type: object
517+
type: array
518+
required:
519+
- outcomes
520+
- ingressName
521+
- namespace
522+
type: object
478523
storageClass:
479524
properties:
480525
checkName:

config/crds/zz_generated.deepcopy.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ func (in *Analyze) DeepCopyInto(out *Analyze) {
2626
*out = new(CustomResourceDefinition)
2727
(*in).DeepCopyInto(*out)
2828
}
29+
if in.Ingress != nil {
30+
in, out := &in.Ingress, &out.Ingress
31+
*out = new(Ingress)
32+
(*in).DeepCopyInto(*out)
33+
}
2934
}
3035

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

552+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
553+
func (in *Ingress) DeepCopyInto(out *Ingress) {
554+
*out = *in
555+
out.AnalyzeMeta = in.AnalyzeMeta
556+
if in.Outcomes != nil {
557+
in, out := &in.Outcomes, &out.Outcomes
558+
*out = make([]*Outcome, len(*in))
559+
for i := range *in {
560+
if (*in)[i] != nil {
561+
in, out := &(*in)[i], &(*out)[i]
562+
*out = new(Outcome)
563+
(*in).DeepCopyInto(*out)
564+
}
565+
}
566+
}
567+
}
568+
569+
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Ingress.
570+
func (in *Ingress) DeepCopy() *Ingress {
571+
if in == nil {
572+
return nil
573+
}
574+
out := new(Ingress)
575+
in.DeepCopyInto(out)
576+
return out
577+
}
578+
547579
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
548580
func (in *Outcome) DeepCopyInto(out *Outcome) {
549581
*out = *in

config/samples/troubleshoot_v1beta1_preflight.yaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ spec:
3333
# message: The top secret secret is missing
3434
# pass:
3535
# message: You know the secret
36-
# - ingress:
37-
# namespace: default
38-
# name: connect-to-me
39-
# fail:
40-
# message: The ingress isn't ingressing
41-
# pass:
42-
# message: All systems ok on ingress
36+
- ingress:
37+
namespace: default
38+
ingressName: connect-to-me
39+
outcomes:
40+
- fail:
41+
message: The ingress isn't ingressing
42+
- pass:
43+
message: All systems ok on ingress
4344
# - imagePullSecret:
4445
# name: replicated
4546
# namespace: my-app

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b h1:aBGgKJUM9Hk/3AE8WaZIApnTxG35kbu
480480
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
481481
k8s.io/api v0.0.0-20190703205437-39734b2a72fe h1:MFaHtAyhZcfBZocN91muHSqnwiF5yfXx7yGoehneNYg=
482482
k8s.io/api v0.0.0-20190703205437-39734b2a72fe/go.mod h1:J5EZ0KSEjvyKOBy5BDHSF3zn82madLLWg7nUKaOHZKU=
483+
k8s.io/api v0.0.0-20190717022910-653c86b0609b h1:WiE134uexhvhHw4DjJuYsghv792UCe2xN5SHQOayf28=
483484
k8s.io/apiextensions-apiserver v0.0.0-20190228180357-d002e88f6236 h1:JfFtjaElBIgYKCWEtYQkcNrTpW+lMO4GJy8NP6SVQmM=
484485
k8s.io/apiextensions-apiserver v0.0.0-20190228180357-d002e88f6236/go.mod h1:IxkesAMoaCRoLrPJdZNZUQp9NfZnzqaVzLhb2VEQzXE=
485486
k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8 h1:q1Qvjzs/iEdXF6A1a8H3AKVFDzJNcJn3nXMs6R6qFtA=

pkg/analyze/analyzer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getCollectedFileContents fun
2626
if analyzer.CustomResourceDefinition != nil {
2727
return analyzeCustomResourceDefinition(analyzer.CustomResourceDefinition, getCollectedFileContents)
2828
}
29+
if analyzer.Ingress != nil {
30+
return analyzeIngress(analyzer.Ingress, getCollectedFileContents)
31+
}
2932

3033
return nil, errors.New("invalid analyzer")
3134
}

pkg/analyze/ingress.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package analyzer
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
8+
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
9+
)
10+
11+
func analyzeIngress(analyzer *troubleshootv1beta1.Ingress, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
12+
ingressData, err := getCollectedFileContents("cluster-resources/storage-classes.json")
13+
if err != nil {
14+
return nil, err
15+
}
16+
17+
var ingresses []extensionsv1beta1.Ingress
18+
if err := json.Unmarshal(ingressData, &ingresses); err != nil {
19+
return nil, err
20+
}
21+
22+
title := analyzer.CheckName
23+
if title == "" {
24+
title = fmt.Sprintf("Ingress %s", analyzer.IngressName)
25+
}
26+
27+
result := AnalyzeResult{
28+
Title: title,
29+
}
30+
31+
for _, ingress := range ingresses {
32+
if ingress.Name == analyzer.IngressName {
33+
result.IsPass = true
34+
for _, outcome := range analyzer.Outcomes {
35+
if outcome.Pass != nil {
36+
result.Message = outcome.Pass.Message
37+
result.URI = outcome.Pass.URI
38+
}
39+
}
40+
41+
return &result, nil
42+
}
43+
}
44+
45+
result.IsFail = true
46+
for _, outcome := range analyzer.Outcomes {
47+
if outcome.Fail != nil {
48+
result.Message = outcome.Fail.Message
49+
result.URI = outcome.Fail.URI
50+
}
51+
}
52+
53+
return &result, nil
54+
}

pkg/apis/troubleshoot/v1beta1/analyzer_shared.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ type CustomResourceDefinition struct {
2929
CustomResourceDefinitionName string `json:"customResourceDefinitionName" yaml:"customResourceDefinitionName"`
3030
}
3131

32+
type Ingress struct {
33+
AnalyzeMeta `json:",inline" yaml:",inline"`
34+
Outcomes []*Outcome `json:"outcomes" yaml:"outcomes"`
35+
IngressName string `json:"ingressName" yaml:"ingressName"`
36+
Namespace string `json:"namespace" yaml:"namespace"`
37+
}
38+
3239
type AnalyzeMeta struct {
3340
CheckName string `json:"checkName,omitempty" yaml:"checkName,omitempty"`
3441
}
@@ -37,4 +44,5 @@ type Analyze struct {
3744
ClusterVersion *ClusterVersion `json:"clusterVersion,omitempty" yaml:"clusterVersion,omitempty"`
3845
StorageClass *StorageClass `json:"storageClass,omitempty" yaml:"storageClass,omitempty"`
3946
CustomResourceDefinition *CustomResourceDefinition `json:"customResourceDefinition,omitempty" yaml:"customResourceDefinition,omitempty"`
47+
Ingress *Ingress `json:"ingress,omitempty" yaml:"ingress,omitempty"`
4048
}

pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ func (in *Analyze) DeepCopyInto(out *Analyze) {
4242
*out = new(CustomResourceDefinition)
4343
(*in).DeepCopyInto(*out)
4444
}
45+
if in.Ingress != nil {
46+
in, out := &in.Ingress, &out.Ingress
47+
*out = new(Ingress)
48+
(*in).DeepCopyInto(*out)
49+
}
4550
}
4651

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

568+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
569+
func (in *Ingress) DeepCopyInto(out *Ingress) {
570+
*out = *in
571+
out.AnalyzeMeta = in.AnalyzeMeta
572+
if in.Outcomes != nil {
573+
in, out := &in.Outcomes, &out.Outcomes
574+
*out = make([]*Outcome, len(*in))
575+
for i := range *in {
576+
if (*in)[i] != nil {
577+
in, out := &(*in)[i], &(*out)[i]
578+
*out = new(Outcome)
579+
(*in).DeepCopyInto(*out)
580+
}
581+
}
582+
}
583+
}
584+
585+
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Ingress.
586+
func (in *Ingress) DeepCopy() *Ingress {
587+
if in == nil {
588+
return nil
589+
}
590+
out := new(Ingress)
591+
in.DeepCopyInto(out)
592+
return out
593+
}
594+
563595
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
564596
func (in *Outcome) DeepCopyInto(out *Outcome) {
565597
*out = *in

0 commit comments

Comments
 (0)