Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Prototype for Chainable Commands #87

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 19 additions & 0 deletions pkg/common/outcomes/dependency.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package outcomes

// DependencyChecks contains checks with their outcome
var DependencyChecks = make(map[string]bool)

// GetCheckOutcome gets check outcome
func GetCheckOutcome(checkName string) bool {
return DependencyChecks[checkName]
}

// AddCheckToMap adds the check with default outcome to false to the DependencyChecks map
func AddCheckToMap(checkName string) {
DependencyChecks[checkName] = false
}

// SetCheckPass sets the check outcome to true if check passes
func SetCheckPass(checkName string) {
DependencyChecks[checkName] = true
}
23 changes: 23 additions & 0 deletions pkg/common/outcomes/skip_outcome.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package outcomes

var _ Outcome = (*SkipOutcome)(nil)

// SkipOutcome is the check outcome for checks that fail or encounter errors.
type SkipOutcome struct {
LongDiagnostics string
}

// GetShortStatus implements outcomes.Outcome.
func (SkipOutcome) GetShortStatus() string {
return "➡️ Skipped"
}

// GetLongDiagnostics implements outcomes.Outcome.
func (o SkipOutcome) GetLongDiagnostics() string {
return o.LongDiagnostics
}

// GetError imeplements outcomes.Outcome.
func (o SkipOutcome) GetError() error {
return nil
}
3 changes: 3 additions & 0 deletions pkg/kubernetes/namespace/injected.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func (check SidecarInjectionCheck) Description() string {

// Run implements common.Runnable
func (check SidecarInjectionCheck) Run() outcomes.Outcome {
if !outcomes.GetCheckOutcome("NamespacesInSameMeshCheck") {
return outcomes.SkipOutcome{LongDiagnostics: "skipped because namespace is not in the mesh"}
}
annotations, err := getAnnotations(check.client, check.namespace)
if err != nil {
fmt.Printf("Error: %s\n", err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/kubernetes/namespace/monitored.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (check NamespacesInSameMeshCheck) Description() string {

// Run implements common.Runnable
func (check NamespacesInSameMeshCheck) Run() outcomes.Outcome {
outcomes.AddCheckToMap("NamespacesInSameMeshCheck")
labelsA, err := getLabels(check.client, check.namespaceA)
if err != nil {
return outcomes.FailedOutcome{Error: err}
Expand All @@ -105,7 +106,7 @@ func (check NamespacesInSameMeshCheck) Run() outcomes.Outcome {
if meshNameA != meshNameB {
return outcomes.FailedOutcome{Error: ErrNamespacesNotInSameMesh}
}

outcomes.SetCheckPass("NamespacesInSameMeshCheck")
return outcomes.SuccessfulOutcomeWithoutDiagnostics{}
}

Expand Down