status

package
v1.17.3 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Overview

Package status contains logic for the nomos status CLI command.

Index

Constants

View Source
const (
	// ACMOperatorLabelSelector is the label selector for the ACM operator Pod.
	ACMOperatorLabelSelector = "k8s-app=config-management-operator"
)

Variables

View Source
var Cmd = &cobra.Command{
	Use: "status",

	Short: `Prints the status of all clusters with Configuration Management installed.`,
	RunE: func(cmd *cobra.Command, args []string) error {

		cmd.SilenceUsage = true

		fmt.Println("Connecting to clusters...")

		clientMap, err := ClusterClients(cmd.Context(), flags.Contexts)
		if err != nil {

			if unWrapped := errors.Cause(err); os.IsNotExist(unWrapped) {
				return errors.Wrapf(err, "failed to create client configs")
			}

			klog.Fatalf("Failed to get clients: %v", err)
		}
		if len(clientMap) == 0 {
			return errors.New("no clusters found")
		}

		names := clusterNames(clientMap)

		writer := util.NewWriter(os.Stdout)
		if pollingInterval > 0 {
			for {
				printStatus(cmd.Context(), writer, clientMap, names)
				time.Sleep(pollingInterval)
			}
		} else {
			printStatus(cmd.Context(), writer, clientMap, names)
		}
		return nil
	},
}

Cmd runs a loop that fetches ACM objects from all available clusters and prints a summary of the status of Config Management for each cluster.

Functions

func ClusterClients

func ClusterClients(ctx context.Context, contexts []string) (map[string]*ClusterClient, error)

ClusterClients returns a map of of typed clients keyed by the name of the kubeconfig context they are initialized from.

func HasRunningPod

func HasRunningPod(pods []corev1.Pod) bool

HasRunningPod returns true if there is a Pod whose phase is running.

func SaveToTempFile

func SaveToTempFile(ctx context.Context, contexts []string) (*os.File, error)

SaveToTempFile writes the `nomos status` output into a temporary file, and opens the file for reading. It returns the file descriptor with read_only permission. Using the temp file instead of os.Pipe is to avoid the hanging issue caused by the os.Pipe buffer limit: 64k. This function is only used in `nomos bugreport` for the `nomos status` output.

Types

type ClusterClient

type ClusterClient struct {
	// Client performs CRUD operations on Kubernetes objects.
	Client client.Client

	// K8sClient contains the clients for groups.
	K8sClient        *kubernetes.Clientset
	ConfigManagement *util.ConfigManagementClient
	// contains filtered or unexported fields
}

ClusterClient is the client that talks to the cluster.

func (*ClusterClient) IsConfigured

func (c *ClusterClient) IsConfigured(ctx context.Context, cs *ClusterState) bool

IsConfigured returns true if the ClusterClient is connected to a cluster where Config Sync is configured. Updates the given ClusterState with status info if Config Sync is not configured.

func (*ClusterClient) IsInstalled

func (c *ClusterClient) IsInstalled(ctx context.Context, cs *ClusterState) bool

IsInstalled returns true if the ClusterClient is connected to a cluster where Config Sync is installed (ACM operator Pod is running). Updates the given ClusterState with status info if Config Sync is not installed.

type ClusterState

type ClusterState struct {
	// Ref is the current cluster context
	Ref string

	// Error represents the sync errors
	Error string
	// contains filtered or unexported fields
}

ClusterState represents the sync status of all repos on a cluster.

type Condition

type Condition struct {
	// type of the condition
	Type string `json:"type"`

	// status of the condition
	Status string `json:"status"`

	// one-word CamelCase reason for the condition’s last transition
	// +optional
	Reason string `json:"reason,omitempty"`

	// human-readable message indicating details about last transition
	// +optional
	Message string `json:"message,omitempty"`

	// last time the condition transit from one status to another
	// +optional
	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
}

Condition is the for the resource status condition

type RepoState

type RepoState struct {
	// contains filtered or unexported fields
}

RepoState represents the sync status of a single repo on a cluster.

func RootRepoStatus

func RootRepoStatus(rs *v1beta1.RootSync, rg *unstructured.Unstructured, syncingConditionSupported bool) *RepoState

RootRepoStatus converts the given RootSync into a RepoState.

func (*RepoState) GetCommit

func (r *RepoState) GetCommit() string

GetCommit returns RepoState's commit

func (*RepoState) GetErrorSummary

func (r *RepoState) GetErrorSummary() *v1beta1.ErrorSummary

GetErrorSummary returns RepoState's ErrorSummary

func (*RepoState) GetStatus

func (r *RepoState) GetStatus() string

GetStatus returns RepoState's status

Jump to

Keyboard shortcuts

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