From 4890f4e0a6774cceca8f0603d7d4c6da630f709c Mon Sep 17 00:00:00 2001 From: Naiming Shen Date: Fri, 18 Oct 2024 18:00:17 -0700 Subject: [PATCH] Initial set of pillar types related files - for cluster multi-node mode, some of the initial pillar side types related files, additional changes will be added in later PRs Signed-off-by: Naiming Shen --- pkg/pillar/types/cipherinfotypes.go | 1 + pkg/pillar/types/clustertypes.go | 85 +++++++++++++++++++++++++++++ pkg/pillar/types/domainmgrtypes.go | 8 +++ pkg/pillar/types/zedkubetypes.go | 83 ++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+) create mode 100644 pkg/pillar/types/clustertypes.go create mode 100644 pkg/pillar/types/zedkubetypes.go diff --git a/pkg/pillar/types/cipherinfotypes.go b/pkg/pillar/types/cipherinfotypes.go index e1b1982c42..e47b148971 100644 --- a/pkg/pillar/types/cipherinfotypes.go +++ b/pkg/pillar/types/cipherinfotypes.go @@ -145,4 +145,5 @@ type EncryptionBlock struct { CellularNetUsername string CellularNetPassword string ProtectedUserData string + ClusterToken string } diff --git a/pkg/pillar/types/clustertypes.go b/pkg/pillar/types/clustertypes.go new file mode 100644 index 0000000000..b8ccd8ee73 --- /dev/null +++ b/pkg/pillar/types/clustertypes.go @@ -0,0 +1,85 @@ +// Copyright (c) 2024 Zededa, Inc. +// SPDX-License-Identifier: Apache-2.0 + +package types + +import ( + "net" + + uuid "github.com/satori/go.uuid" +) + +const ( + // ClusterStatusPort - Port for k3s server for cluster status advertise + // See more detail description in pkg/pillar/docs/zedkube.md + ClusterStatusPort = "12346" +) + +// EdgeNodeClusterConfig - Configuration for cluster multi-node from controller +type EdgeNodeClusterConfig struct { + ClusterName string + ClusterID UUIDandVersion + // ClusterInterface - Interface to be used for kubernetes cluster for the node. + // This can be a Management interface or an App-Shared interface. This is a logical + // label of the port. + ClusterInterface string + // ClusterIPPrefix - IP Prefix for the kubernetes cluster Node IP. This IP prefix is + // applied to the ClusterInterface. It can be the only IP prefix on the interface, or + // it can be the 2nd IP prefix on the interface. + ClusterIPPrefix *net.IPNet + // IsWorkerNode - Is this node a worker node in the cluster, vs a kubernetes server node + IsWorkerNode bool + // JoinServerIP - The kubernetes server IP address to join for this node as part of the + // multi-node cluster + JoinServerIP net.IP + // BootstrapNode - Is this node the bootstrap node for the cluster. In bringing up the + // kubernetes cluster, one node is designated as the bootstrap node in HA server mode. + // This node needs to be up first before other nodes can join the cluster. This BootstrapNode + // will own the 'JoinServerIP' on it's cluster interface. + BootstrapNode bool + + // CipherBlockStatus, for encrypted cluster token data + CipherToken CipherBlockStatus +} + +// ENClusterAppStatus - Status of an App Instance in the multi-node cluster +type ENClusterAppStatus struct { + AppUUID uuid.UUID // UUID of the appinstance + IsDNidNode bool // DesignatedNodeID is set on the App for this node + ScheduledOnThisNode bool // App is running on this device + StatusRunning bool // Status of the app in "Running" state + IsVolumeDetached bool // Are volumes detached after failover ? +} + +// Key - returns the key for the config of EdgeNodeClusterConfig +func (config EdgeNodeClusterConfig) Key() string { + return config.ClusterID.UUID.String() +} + +// EdgeNodeClusterStatus - Status of the multi-node cluster published by zedkube +type EdgeNodeClusterStatus struct { + ClusterName string + ClusterID UUIDandVersion + // ClusterInterface - Interface to be used for kubernetes cluster for the node. + // This can be a Management interface or an App-Shared interface. This is a logical + // label of the port. + ClusterInterface string + // ClusterIPPrefix - IP Prefix for the kubernetes cluster Node IP. This IP prefix is + // applied to the ClusterInterface. It can be the only IP prefix on the interface, or + // it can be the 2nd IP prefix on the interface. + ClusterIPPrefix *net.IPNet + // ClusterIPIsReady - Is the cluster IP address ready on the cluster interface + ClusterIPIsReady bool + // IsWorkerNode - Is this node a worker node in the cluster, vs a kubernetes server node + IsWorkerNode bool + // JoinServerIP - The kubernetes server IP address to join for this node as part of the + // multi-node cluster + JoinServerIP net.IP + // BootstrapNode - Is this node the bootstrap node for the cluster. In bringing up the + // kubernetes cluster, one node is designated as the bootstrap node in HA server mode. + // This node needs to be up first before other nodes can join the cluster. This BootstrapNode + // will own the 'JoinServerIP' on it's cluster interface. + BootstrapNode bool + + Error ErrorDescription +} diff --git a/pkg/pillar/types/domainmgrtypes.go b/pkg/pillar/types/domainmgrtypes.go index 3e7bd762cc..79bb127738 100644 --- a/pkg/pillar/types/domainmgrtypes.go +++ b/pkg/pillar/types/domainmgrtypes.go @@ -42,6 +42,8 @@ type DomainConfig struct { // KubeImageName: is the container image reference we pass to domainmgr to launch a native container // in kubevirt eve KubeImageName string + // if this node is the DNiD of the App + IsDNidNode bool // XXX: to be deprecated, use CipherBlockStatus instead CloudInitUserData *string `json:"pubsub-large-CloudInitUserData"` // base64-encoded @@ -321,6 +323,11 @@ type DomainStatus struct { // FmlCustomResolution is the custom resolution for FML mode, // xxx: this should be moved to VmConfig FmlCustomResolution string + // if this node is the DNiD of the App + IsDNidNode bool + // the device name is used for kube node name + // Need to pass in from domainmgr to hypervisor context commands + NodeName string } func (status DomainStatus) Key() string { @@ -474,6 +481,7 @@ type DomainMetric struct { UsedMemoryPercent float64 LastHeard time.Time Activated bool + NodeName string // the name of the kubernetes node on which the app is currently running } // Key returns the key for pubsub diff --git a/pkg/pillar/types/zedkubetypes.go b/pkg/pillar/types/zedkubetypes.go new file mode 100644 index 0000000000..f64bfda0ab --- /dev/null +++ b/pkg/pillar/types/zedkubetypes.go @@ -0,0 +1,83 @@ +// Copyright (c) 2024 Zededa, Inc. +// SPDX-License-Identifier: Apache-2.0 + +package types + +import "time" + +// KubeNodeStatus - Enum for the status of a Kubernetes node +type KubeNodeStatus int8 + +const ( + KubeNodeStatusUnknown KubeNodeStatus = iota // KubeNodeStatusUnknown - Node status is unknown + KubeNodeStatusReady // KubeNodeStatusReady - Node is in ready status + KubeNodeStatusNotReady // KubeNodeStatusNotReady - Node is in not ready status + KubeNodeStatusNotReachable // KubeNodeStatusNotReachable - Node is not reachable +) + +// KubeNodeInfo - Information about a Kubernetes node +type KubeNodeInfo struct { + Name string + Status KubeNodeStatus + IsMaster bool + UsesEtcd bool + CreationTime time.Time + LastTransitionTime time.Time + KubeletVersion string + InternalIP string + ExternalIP string + Schedulable bool +} + +// KubePodStatus - Enum for the status of a Kubernetes pod +type KubePodStatus int8 + +const ( + KubePodStatusUnknown KubePodStatus = iota // KubePodStatusUnknown - Pod status is unknown + KubePodStatusPending // KubePodStatusPending - Pod is in pending status + KubePodStatusRunning // KubePodStatusRunning - Pod is in running status + KubePodStatusSucceeded // KubePodStatusSucceeded - Pod is in succeeded status + KubePodStatusFailed // KubePodStatusFailed - Pod is in failed status +) + +// KubePodInfo - Information about a Kubernetes pod +type KubePodInfo struct { + Name string + Status KubePodStatus + RestartCount int32 + RestartTimestamp time.Time + CreationTimestamp time.Time + PodIP string + NodeName string +} + +// KubeVMIStatus - Enum for the status of a VirtualMachineInstance +type KubeVMIStatus int8 + +const ( + KubeVMIStatusUnset KubeVMIStatus = iota // KubeVMIStatusUnset - UnSet VMI status + KubeVMIStatusPending // KubeVMIStatusPending - VMI in pending status + KubeVMIStatusScheduling // KubeVMIStatusScheduling - VMI in Scheduling status + KubeVMIStatusScheduled // KubeVMIStatusScheduled - VMI in Scheduled status + KubeVMIStatusRunning // KubeVMIStatusRunning - VMI in Running status + KubeVMIStatusSucceeded // KubeVMIStatusSucceeded - VMI in Succeeded status + KubeVMIStatusFailed // KubeVMIStatusFailed - VMI in Failed status + KubeVMIStatusUnknown // KubeVMIStatusUnknown - VMI in Unknown status +) + +// KubeVMIInfo - Information about a VirtualMachineInstance +type KubeVMIInfo struct { + Name string + Status KubeVMIStatus + CreationTime time.Time + LastTransitionTime time.Time + IsReady bool + NodeName string +} + +// KubeClusterInfo - Information about a Kubernetes cluster +type KubeClusterInfo struct { + Nodes []KubeNodeInfo // List of nodes in the cluster + AppPods []KubePodInfo // List of EVE application pods + AppVMIs []KubeVMIInfo // List of VirtualMachineInstance +}