cd

package
v0.0.0-...-6cdb919 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeploymentPodTemplateHash = "pod-template-hash"

	RolloutPodTemplateHash = "rollouts-pod-template-hash"
)
View Source
const (
	// PodLifeCycleSchedule specifies whether pod has been scheduled
	PodLifeCycleSchedule = "PodSchedule"
	// PodLifeCycleInitialize specifies whether all init containers have finished
	PodLifeCycleInitialize = "PodInitialize"
	// PodLifeCycleContainerStartup specifies whether the container has passed its startup probe
	PodLifeCycleContainerStartup = "ContainerStartup"
	// PodLifeCycleContainerOnline specified whether the container has passed its postStart hook
	PodLifeCycleContainerOnline = "ContainerOnline"
	// PodLifeCycleHealthCheck specifies whether the container has passed its readiness probe
	PodLifeCycleHealthCheck = "HealthCheck"
	// PodLifeCycleContainerPreStop specifies whether the container is executing preStop hook
	PodLifeCycleContainerPreStop = "PreStop"

	LifeCycleStatusSuccess  = "Success"
	LifeCycleStatusWaiting  = "Waiting"
	LifeCycleStatusRunning  = "Running"
	LifeCycleStatusAbnormal = "Abnormal"

	PodErrCrashLoopBackOff = "CrashLoopBackOff"
)

Variables

View Source
var (
	GKPod = schema.GroupKind{
		Group: "",
		Kind:  "Pod",
	}
)

Functions

func CompareRevision

func CompareRevision(ctx context.Context, rs1, rs2 *appsv1.ReplicaSet) bool

CompareRevision return true if rs1 is the newer one, return false otherwise.

Types

type CD

type CD interface {
	CreateCluster(ctx context.Context, params *CreateClusterParams) error
	DeployCluster(ctx context.Context, params *DeployClusterParams) error
	DeleteCluster(ctx context.Context, params *DeleteClusterParams) error
	GetClusterState(ctx context.Context, params *GetClusterStateV2Params) (*ClusterStateV2, error)
	GetResourceTree(ctx context.Context, params *GetResourceTreeParams) ([]ResourceNode, error)
	GetStep(ctx context.Context, params *GetStepParams) (*Step, error)
	GetPodEvents(ctx context.Context, params *GetPodEventsParams) ([]Event, error)
}

func NewCD

func NewCD(informerFactories *regioninformers.RegionInformers, clusterGitRepo gitrepo.ClusterGitRepo,
	argoCDMapper argocdconf.Mapper, regionArgoCDMapper argocdconf.RegionMapper, targetRevision string) CD

type ClusterPod

type ClusterPod struct {
	Metadata          PodMetadata  `json:"metadata,omitempty" yaml:"metadata,omitempty"`
	Spec              PodSpec      `json:"spec,omitempty" yaml:"spec,omitempty"`
	Status            PodStatus    `json:"status,omitempty" yaml:"status,omitempty"`
	DeletionTimestamp *metav1.Time `json:"deletionTimestamp,omitempty"`
}

ClusterPod pod detail

type ClusterState

type ClusterState struct {
	// Status:
	// Processing
	// Healthy
	// Suspended
	// Degraded
	// Missing
	// Unknown
	Status health.HealthStatusCode `json:"status,omitempty" yaml:"status,omitempty"`

	// Step
	Step *Step `json:"step"`

	// Replicas the actual number of replicas running in k8s
	Replicas int `json:"replicas,omitempty" yaml:"replicas,omitempty"`

	// DesiredReplicas desired replicas
	DesiredReplicas *int `json:"desiredReplicas,omitempty" yaml:"desiredReplicas,omitempty"`

	// PodTemplateHash
	PodTemplateHash string `json:"podTemplateHash,omitempty" yaml:"podTemplateHash,omitempty"`

	// PodTemplateHashKey label key from Deployment or Rollout
	PodTemplateHashKey string `json:"podTemplateHashKey,omitempty" yaml:"podTemplateHashKey,omitempty"`

	// Revision the desired revision
	Revision string `json:"revision,omitempty" yaml:"revision,omitempty"`

	// Versions versions detail
	// key is pod-template-hash, if equal to PodTemplateHash, the version is the desired version
	Versions map[string]*ClusterVersion `json:"versions,omitempty" yaml:"versions,omitempty"`

	// ManualPaused indicates whether the cluster is in manual pause state
	ManualPaused bool `json:"manualPaused" yaml:"manualPaused"`
}

ClusterState cluster state

type ClusterStateV2

type ClusterStateV2 struct {
	Status string `json:"status"`
}

type ClusterVersion

type ClusterVersion struct {
	// Replicas the replicas of this revision
	Replicas int    `json:"replicas,omitempty" yaml:"replicas,omitempty"`
	Revision string `json:"revision,omitempty" yaml:"revision,omitempty"`
	// Pods the pods detail of this revision, the key is pod name
	Pods map[string]*ClusterPod `json:"pods,omitempty" yaml:"pods,omitempty"`
}

ClusterVersion version information

type CompactContainer

type CompactContainer struct {
	Name           string        `json:"name"`
	Image          string        `json:"image"`
	ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`
}

func ContainerCompact

func ContainerCompact(container corev1.Container) CompactContainer

type CompactPod

type CompactPod struct {
	Metadata CompactPodMetadata `json:"metadata"`
	Spec     CompactPodSpec     `json:"spec"`
	Status   CompactPodStatus   `json:"status"`
}

func Compact

func Compact(pod corev1.Pod) CompactPod

type CompactPodMetadata

type CompactPodMetadata struct {
	Name              string            `json:"name"`
	Namespace         string            `json:"namespace"`
	CreationTimestamp metav1.Time       `json:"creationTimestamp"`
	DeletionTimestamp *metav1.Time      `json:"deletionTimestamp"`
	Labels            map[string]string `json:"labels"`
	Annotations       map[string]string `json:"annotations"`
}

for pod compact

type CompactPodSpec

type CompactPodSpec struct {
	InitContainers []CompactContainer `json:"initContainers"`
	Containers     []CompactContainer `json:"containers"`
}

type CompactPodStatus

type CompactPodStatus struct {
	Phase             corev1.PodPhase          `json:"phase"`
	Conditions        []corev1.PodCondition    `json:"conditions"`
	PodIP             string                   `json:"podIP"`
	ContainerStatuses []corev1.ContainerStatus `json:"containerStatuses"`
}

type Container

type Container struct {
	Name  string `json:"name,omitempty" yaml:"name,omitempty"`
	Image string `json:"image,omitempty" yaml:"image,omitempty"`
}

type ContainerDetail

type ContainerDetail struct {
	// Name of the container.
	Name string `json:"name"`

	// Image URI of the container.
	Image string `json:"image"`

	// List of environment variables.
	Env []corev1.EnvVar `json:"env"`

	// Commands of the container
	Commands []string `json:"commands"`

	// Command arguments
	Args []string `json:"args"`

	// Information about mounted volumes
	VolumeMounts []VolumeMount `json:"volumeMounts"`

	// Security configuration that will be applied to a container.
	SecurityContext *corev1.SecurityContext `json:"securityContext"`

	// Status of a pod container
	Status *corev1.ContainerStatus `json:"status"`

	// Probes
	LivenessProbe  *corev1.Probe `json:"livenessProbe"`
	ReadinessProbe *corev1.Probe `json:"readinessProbe"`
	StartupProbe   *corev1.Probe `json:"startupProbe"`
}

ContainerDetail represents more information about a container

type ContainerState

type ContainerState struct {
	State     string       `json:"state" yaml:"state"`
	Reason    string       `json:"reason" yaml:"reason"`
	Message   string       `json:"message" yaml:"message"`
	StartedAt *metav1.Time `json:"startedAt,omitempty"`
}

type ContainerStatus

type ContainerStatus struct {
	Name         string         `json:"name,omitempty" yaml:"name,omitempty"`
	Ready        bool           `json:"ready" yaml:"ready"`
	RestartCount int32          `json:"restartCount"`
	State        ContainerState `json:"state" yaml:"state"`
	ImageID      string         `json:"imageID" yaml:"imageID"`
}

type CreateClusterParams

type CreateClusterParams struct {
	Environment  string
	Cluster      string
	GitRepoURL   string
	ValueFiles   []string
	RegionEntity *regionmodels.RegionEntity
	Namespace    string
}

type DeleteClusterParams

type DeleteClusterParams struct {
	Environment string
	Cluster     string
	Region      string
}

type DeletePodsParams

type DeletePodsParams struct {
	RegionEntity *regionmodels.RegionEntity
	Namespace    string
	Pods         []string
}

type DeployClusterParams

type DeployClusterParams struct {
	Environment string
	Cluster     string
	Revision    string
	Region      string
}

type Event

type Event struct {
	Type           string      `json:"type" yaml:"type"`
	Reason         string      `json:"reason,omitempty" yaml:"reason,omitempty"`
	Message        string      `json:"message,omitempty" yaml:"message,omitempty"`
	Count          int32       `json:"count,omitempty" yaml:"count,omitempty"`
	EventTimestamp metav1.Time `json:"eventTimestamp,omitempty" yaml:"eventTimestamp,omitempty"`
}

type ExecParams

type ExecParams struct {
	Commands     []string
	Environment  string
	Cluster      string
	RegionEntity *regionmodels.RegionEntity
	Namespace    string
	PodList      []string
}

type ExecResp

type ExecResp struct {
	Result bool
	Stdout string
	Stderr string
	Error  error
	// contains filtered or unexported fields
}

type ExecuteActionParams

type ExecuteActionParams struct {
	RegionEntity *regionmodels.RegionEntity
	Namespace    string
	Action       string
	GVR          schema.GroupVersionResource
	ResourceName string
	ClusterID    uint
}

type GetClusterStateParams

type GetClusterStateParams struct {
	Environment  string
	Cluster      string
	RegionEntity *regionmodels.RegionEntity
}

type GetClusterStateV2Params

type GetClusterStateV2Params struct {
	Application  string
	Environment  string
	Cluster      string
	RegionEntity *regionmodels.RegionEntity
}

type GetContainerLogParams

type GetContainerLogParams struct {
	RegionEntity *regionmodels.RegionEntity
	Namespace    string
	Cluster      string
	Pod          string
	Container    string
	Environment  string
	TailLines    int64
}

type GetPodEventsParams

type GetPodEventsParams struct {
	RegionEntity *regionmodels.RegionEntity
	Environment  string
	Cluster      string
	Namespace    string
	Pod          string
}

type GetPodParams

type GetPodParams struct {
	RegionEntity *regionmodels.RegionEntity
	Cluster      string
	Namespace    string
	Pod          string
}

type GetResourceTreeParams

type GetResourceTreeParams struct {
	Environment  string
	Cluster      string
	RegionEntity *regionmodels.RegionEntity
}

type GetStepParams

type GetStepParams struct {
	Environment  string
	Cluster      string
	RegionEntity *regionmodels.RegionEntity
}

type K8sUtil

type K8sUtil interface {
	Exec(ctx context.Context, params *ExecParams) (map[string]ExecResp, error)
	DeletePods(ctx context.Context, params *DeletePodsParams) (map[string]OperationResult, error)
	ExecuteAction(ctx context.Context, params *ExecuteActionParams) error
	GetPodContainers(ctx context.Context, params *GetPodParams) ([]ContainerDetail, error)
	GetPod(ctx context.Context, params *GetPodParams) (*corev1.Pod, error)
	GetContainerLog(ctx context.Context, params *GetContainerLogParams) (<-chan string, error)
}

func NewK8sUtil

func NewK8sUtil(factories *regioninformers.RegionInformers, mgr eventmanager.Manager) K8sUtil

type LegacyCD

type LegacyCD interface {
	CD

	GetClusterStateV1(ctx context.Context, params *GetClusterStateParams) (*ClusterState, error)
}

nolint

type LifeCycleItem

type LifeCycleItem struct {
	Type         string      `json:"type" yaml:"type"`
	Status       string      `json:"status" yaml:"status"`
	Message      string      `json:"message" yaml:"status"`
	CompleteTime metav1.Time `json:"completeTime" yaml:"completeTime"`
}

type OperationResult

type OperationResult struct {
	Result bool
	Error  error
}

type PodMetadata

type PodMetadata struct {
	CreationTimestamp metav1.Time       `json:"creationTimestamp"`
	Namespace         string            `json:"namespace,omitempty" yaml:"namespace,omitempty"`
	Annotations       map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
}

type PodSpec

type PodSpec struct {
	NodeName       string       `json:"nodeName,omitempty" yaml:"nodeName,omitempty"`
	InitContainers []*Container `json:"initContainers,omitempty" yaml:"initContainers,omitempty"`
	Containers     []*Container `json:"containers,omitempty" yaml:"containers,omitempty"`
}

type PodStatus

type PodStatus struct {
	HostIP            string             `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
	PodIP             string             `json:"podIP,omitempty" yaml:"podIP,omitempty"`
	Phase             string             `json:"phase,omitempty" yaml:"phase,omitempty"`
	Events            []Event            `json:"events,omitempty" yaml:"events,omitempty"`
	ContainerStatuses []*ContainerStatus `json:"containerStatuses,omitempty" yaml:"containerStatuses,omitempty"`
	LifeCycle         []*LifeCycleItem   `json:"lifeCycle" yaml:"lifeCycle"`
}

type ResourceNode

type ResourceNode struct {
	applicationV1alpha1.ResourceNode
	PodDetail *CompactPod
}

type ResourceTreeNode

type ResourceTreeNode struct {
	*applicationV1alpha1.ResourceNode
	// contains filtered or unexported fields
}

type Step

type Step struct {
	Index        int     `json:"index"`
	Total        int     `json:"total"`
	Replicas     []int   `json:"replicas"`
	ManualPaused bool    `json:"manualPaused"`
	AutoPromote  bool    `json:"autoPromote"`
	Extra        *string `json:"extra"`
}

type TraverseOperator

type TraverseOperator func(node *ResourceTreeNode) bool

TraverseOperator stops if result is false

type VolumeMount

type VolumeMount struct {
	// Name of the variable.
	Name string `json:"name"`

	// Is the volume read only ?
	ReadOnly bool `json:"readOnly"`

	// Path within the container at which the volume should be mounted. Must not contain ':'.
	MountPath string `json:"mountPath"`

	// Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root).
	SubPath string `json:"subPath"`

	// Information about the Volume itself
	Volume corev1.Volume `json:"volume"`
}

Jump to

Keyboard shortcuts

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