Skip to content

Commit

Permalink
Merge pull request #480 from duanmengkk/feature_globalnode
Browse files Browse the repository at this point in the history
add implement of globalnode
  • Loading branch information
duanmengkk authored Apr 25, 2024
2 parents f3ca7a9 + 2a6281f commit 55dd351
Show file tree
Hide file tree
Showing 28 changed files with 1,019 additions and 282 deletions.
93 changes: 93 additions & 0 deletions deploy/crds/kosmos.io_globalnodes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.0
creationTimestamp: null
name: globalnodes.kosmos.io
spec:
group: kosmos.io
names:
kind: GlobalNode
listKind: GlobalNodeList
plural: globalnodes
singular: globalnode
scope: Cluster
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
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:
description: Spec is the specification for the behaviour of the GlobalNodeSpec.
properties:
labels:
additionalProperties:
type: string
description: Set is a map of label:value. It implements Labels.
type: object
nodeIP:
type: string
state:
default: free
type: string
type: object
status:
properties:
conditions:
description: 'Conditions is an array of current observed node conditions.
More info: https://kubernetes.io/docs/concepts/nodes/node/#condition'
items:
description: NodeCondition contains condition information for a
node.
properties:
lastHeartbeatTime:
description: Last time we got an update on a given condition.
format: date-time
type: string
lastTransitionTime:
description: Last time the condition transit from one status
to another.
format: date-time
type: string
message:
description: Human readable message indicating details about
last transition.
type: string
reason:
description: (brief) reason for the condition's last transition.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of node condition.
type: string
required:
- status
- type
type: object
type: array
virtualCluster:
type: string
type: object
required:
- spec
type: object
served: true
storage: true
subresources:
status: {}
2 changes: 2 additions & 0 deletions deploy/crds/kosmos.io_virtualclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ spec:
the kubernetes's control plane
format: int32
type: integer
required:
- nodeCount
type: object
type: array
promoteResources:
Expand Down
24 changes: 24 additions & 0 deletions hack/generate_globalnode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

if [ -z "$KUBECONFIG" ]; then
echo "KUBECONFIG环境变量未设置."
exit 1
fi

nodes=$(kubectl get nodes -o jsonpath='{.items[*].metadata.name}')
for node in ${nodes}; do
nodeIP=$(kubectl get node ${node} -o jsonpath='{.status.addresses[0].address}')
labels=$(kubectl get node ${node} -o jsonpath='{.metadata.labels}')
labelsFormatted=$(echo "$labels" | jq -r 'to_entries | .[] | " \(.key): \(.value)"')
echo "
apiVersion: kosmos.io/v1alpha1
kind: GlobalNode
metadata:
name: ${node}
spec:
nodeIP: \"${nodeIP}\"
labels:
$(echo "${labelsFormatted}" | sed 's/=/": "/g' | awk '{print " " $0}')
" | kubectl apply -f -

done
2 changes: 1 addition & 1 deletion pkg/apis/kosmos/v1alpha1/clusterpodconvertpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ClusterPodConvertPolicySpec struct {

// A label query over a set of resources.
// If name is not empty, LeafNodeSelector will be ignored.
// +option
// +optional
LeafNodeSelector *metav1.LabelSelector `json:"leafNodeSelector,omitempty"`

// Converters are some converter for convert pod when pod synced from root cluster to leaf cluster
Expand Down
63 changes: 63 additions & 0 deletions pkg/apis/kosmos/v1alpha1/global_node_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
)

// +genclient
// +genclient:nonNamespaced
// +kubebuilder:resource:scope="Cluster"
// +kubebuilder:subresource:status
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type GlobalNode struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec is the specification for the behaviour of the GlobalNodeSpec.
// +required
Spec GlobalNodeSpec `json:"spec"`

// +optional
Status GlobalNodeStatus `json:"status,omitempty"`
}

type GlobalNodeSpec struct {
// +optional
NodeIP string `json:"nodeIP,omitempty"`

// +kubebuilder:default=free
// +optional
State NodeState `json:"state,omitempty"`

// +optional
Labels labels.Set `json:"labels,omitempty"`
}

type NodeState string

const (
NodeInUse NodeState = "occupied"
NodeFreeState NodeState = "free"
NodeReserved NodeState = "reserved"
)

type GlobalNodeStatus struct {
// +optional
VirtualCluster string `json:"virtualCluster,omitempty"`

// Conditions is an array of current observed node conditions.
// More info: https://kubernetes.io/docs/concepts/nodes/node/#condition
// +optional
Conditions []corev1.NodeCondition `json:"conditions,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type GlobalNodeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []GlobalNode `json:"items"`
}
6 changes: 3 additions & 3 deletions pkg/apis/kosmos/v1alpha1/virtualcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type VirtualClusterSpec struct {
ExternalIP string `json:"externalIP,omitempty"`

// PromotePolicies definites the policies for promote to the kubernetes's control plane
// +optional
// +required
PromotePolicies []PromotePolicy `json:"promotePolicies,omitempty"`

// PromoteResources definites the resources for promote to the kubernetes's control plane,
Expand All @@ -65,8 +65,8 @@ type PromotePolicy struct {
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`

// NodeCount is the number of nodes to promote to the kubernetes's control plane
// +optional
NodeCount *int32 `json:"nodeCount,omitempty"`
// +required
NodeCount int32 `json:"nodeCount"`
}

type PromoteResources struct {
Expand Down
113 changes: 108 additions & 5 deletions pkg/apis/kosmos/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 2 additions & 0 deletions pkg/apis/kosmos/v1alpha1/zz_generated.register.go

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

Loading

0 comments on commit 55dd351

Please sign in to comment.