Skip to content

Commit

Permalink
add nodeRuntime cr to track cni status
Browse files Browse the repository at this point in the history
Signed-off-by: l1b0k <[email protected]>
  • Loading branch information
l1b0k committed Oct 22, 2024
1 parent b408c2f commit d637d7f
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 0 deletions.
65 changes: 65 additions & 0 deletions pkg/apis/crds/network.alibabacloud.com_noderuntimes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
name: noderuntimes.network.alibabacloud.com
spec:
group: network.alibabacloud.com
names:
kind: NodeRuntime
listKind: NodeRuntimeList
plural: noderuntimes
singular: noderuntime
scope: Cluster
versions:
- name: v1beta1
schema:
openAPIV3Schema:
description: NodeRuntime is the Schema for the per node runtime API
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
type: object
status:
properties:
pods:
additionalProperties:
properties:
podID:
type: string
status:
description: when pod is added
enum:
- initial
- deleted
type: string
required:
- podID
- status
type: object
description: runtime status, indexed by pod uid
type: object
type: object
type: object
served: true
storage: true
subresources:
status: {}
7 changes: 7 additions & 0 deletions pkg/apis/crds/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
CRDPodENI = "podenis.network.alibabacloud.com"
CRDPodNetworking = "podnetworkings.network.alibabacloud.com"
CRDNode = "nodes.network.alibabacloud.com"
CRDNodeRuntime = "noderuntimes.network.alibabacloud.com"

crdVersionKey = "crd.network.alibabacloud.com/version"
)
Expand All @@ -35,6 +36,9 @@ var (

//go:embed network.alibabacloud.com_nodes.yaml
crdsNode []byte

//go:embed network.alibabacloud.com_noderuntimes.yaml
crdsNodeRuntime []byte
)

func getCRD(name string) apiextensionsv1.CustomResourceDefinition {
Expand All @@ -50,6 +54,9 @@ func getCRD(name string) apiextensionsv1.CustomResourceDefinition {
case CRDNode:
crdBytes = crdsNode
version = "v0.2.0"
case CRDNodeRuntime:
crdBytes = crdsNodeRuntime
version = "v0.1.0"
default:
panic(fmt.Sprintf("crd %s name not exist", name))
}
Expand Down
57 changes: 57 additions & 0 deletions pkg/apis/network.alibabacloud.com/v1beta1/node_runtime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type RuntimePodSpec struct {
UID string `json:"uid"`
Name string `json:"name"`
Namespace string `json:"namespace"`
IPv4 string `json:"ipv4"`
IPv6 string `json:"ipv6"`
}

// +kubebuilder:validation:Enum=initial;deleted
type CNIStatus string

const (
CNIStatusInitial CNIStatus = "initial"
CNIStatusDeleted CNIStatus = "deleted"
)

type RuntimePodStatus struct {
PodID string `json:"podID"`
// when pod is added
Status CNIStatus `json:"status"`
}

type NodeRuntimeSpec struct {
}

type NodeRuntimeStatus struct {
// runtime status, indexed by pod uid
Pods map[string]*RuntimePodStatus `json:"pods,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster

// NodeRuntime is the Schema for the per node runtime API
type NodeRuntime struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NodeRuntimeSpec `json:"spec,omitempty"`
Status NodeRuntimeStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// NodeRuntimeList contains a list of Node
type NodeRuntimeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NodeRuntime `json:"items"`
}
2 changes: 2 additions & 0 deletions pkg/apis/network.alibabacloud.com/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&PodNetworkingList{},
&Node{},
&NodeList{},
&NodeRuntime{},
&NodeRuntimeList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
135 changes: 135 additions & 0 deletions pkg/apis/network.alibabacloud.com/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d637d7f

Please sign in to comment.