status

package
v0.0.0-...-b2ee0ae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package status provides warning and failure checks for the status of K8s object based on the various properties of the object status. It's mostly based on kstatus and helps verify if the object status adheres to the kstatus standards.

These checks are documented in detail in https://gist.github.com/darkowlzz/30c31f2e81c48b20398edc082d4fcc96.

Example usage:

import (
    ...
    "github.com/darkowlzz/controller-check/status"
)

func TestFoo() {
    obj := &testapi.Obj{}
    obj.Name = "test-obj"
    obj.Namespace = "test-ns"

    // Initialize the environment, create the object.
    ...

    // Create a status checker with context about the controller. In this
    // case, TestCondition1 and TestCondition2 are the negative polarity
    // conditions supported by the Obj controller.
    conditions := &status.Conditions{NegativePolarity: []string{"TestCondition1", "TestCondition2"}}
    checker := status.NewChecker(client, conditions)

    // Check object status.
    checker.CheckErr(context.TODO(), obj)
}

Example result:

[Check-WARN]: Ready condition should have the value of the negative polarity conditon that's present with the highest priority: Ready != TestCondition1
Diff:
 {
- Reason: "SomeReason",
- Message: "SomeMsg",
+ Reason: "Rsn",
+ Message: "Msg",
 }

In the above example result, the Ready condition values don't match with the negative poliarity condition values. A diff is shown, comparing the Ready condition values and the TestCondition1 condition values that don't match.

Another example result:

[Check-FAIL]: Ready condition must always be present

The above result shows a failure due to a strict check. The Ready condition is expected to always be present.

When used in unit-tests, the checker can be configured to disable fetching a new version of the object using the K8s client and analyze the given object.

checker.DisableFetch = true

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HighestNegativePriorityCondition

func HighestNegativePriorityCondition(conditions *Conditions, condns []metav1.Condition) (*metav1.Condition, error)

HighestNegativePriorityCondition returns the negative priority condition supported by the controller which has the highest priority among the provided conditions.

Types

type Checker

type Checker struct {
	// K8s client, to fetch the latest version of an object.
	client.Client

	// DisableFetch disables fetching the latest state of an object using the
	// client. This can be used in unit-tests, while passing an object with
	// all the properties to be checked.
	DisableFetch bool
	// Stdout of the checker.
	Stdout io.Writer
	// Stderr of the checker.
	Stderr io.Writer
	// contains filtered or unexported fields
}

Checker performs all the status checks. It is configured to provide context of the target controller.

func NewChecker

func NewChecker(cli client.Client, condns *Conditions) *Checker

NewChecker constructs and returns a new Checker for a controller.

func (Checker) Check

func (c Checker) Check(ctx context.Context, obj conditions.Getter) (fail, warn error)

Check performs all the warn and fail checks and returns the results.

func (Checker) CheckErr

func (c Checker) CheckErr(ctx context.Context, obj conditions.Getter)

CheckErr performs all the warn and fail checks and prints them to stdout and stderr, and exits. This is to be used in CLI.

type Conditions

type Conditions struct {
	// NegativePolarity conditions are conditions that have abnormal-true
	// nature.
	NegativePolarity []string `json:"negativePolarity"`
	// PositivePolarity conditions are conditions that have normal-true nature.
	// (Optional)
	PositivePolarity []string `json:"positivePolarity"`
}

Conditions contain the list of status conditions supported by a controller for an object kind.

func ParseConditions

func ParseConditions(input []byte) (*Conditions, error)

ParseConditions parses a given byte slice input into a Conditions object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL