forked from kosmos-io/kosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: duanmengkk <[email protected]>
- Loading branch information
1 parent
16c8815
commit ec02f16
Showing
29 changed files
with
1,036 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: kosmos.io/v1alpha1 | ||
kind: GlobalNode | ||
metadata: | ||
name: example-globalnode | ||
spec: | ||
nodeIP: "12.7" | ||
labels: # Optional: fill in key-value pairs as needed | ||
exampleKey: "exampleValue" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
# 确保提供了kubeconfig路径 | ||
if [ -z "$KUBECONFIG" ]; then | ||
echo "KUBECONFIG环境变量未设置." | ||
exit 1 | ||
fi | ||
|
||
# 获取所有node的名称 | ||
nodes=$(kubectl get nodes -o jsonpath='{.items[*].metadata.name}') | ||
# 遍历所有node | ||
for node in ${nodes}; do | ||
# 获取node的IP地址 | ||
nodeIP=$(kubectl get node ${node} -o jsonpath='{.status.addresses[0].address}') | ||
# 获取node的标签,并转换为GlobalNode需要的格式 | ||
labels=$(kubectl get node ${node} -o jsonpath='{.metadata.labels}') | ||
labelsFormatted=$(echo "$labels" | jq -r 'to_entries | .[] | " \(.key): \(.value)"') | ||
# 使用echo和管道将YAML直接传递给kubectl apply -f - | ||
echo " | ||
apiVersion: kosmos.io/v1alpha1 | ||
kind: GlobalNode | ||
metadata: | ||
name: ${node}-globalnode | ||
spec: | ||
nodeIP: \"${nodeIP}\" | ||
labels: | ||
$(echo "${labelsFormatted}" | sed 's/=/": "/g' | awk '{print " " $0}') | ||
" | kubectl apply -f - | ||
|
||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.