Skip to content

Commit

Permalink
feat: upgrade nodepool crd to v1beta2 (#2266)
Browse files Browse the repository at this point in the history
* feat: upgrade nodepool crd to v1beta2

Co-authored-by: Simon Tien <[email protected]>
  • Loading branch information
tnsimon and Simon Tien authored Jan 22, 2025
1 parent d918606 commit 470292f
Show file tree
Hide file tree
Showing 51 changed files with 2,519 additions and 769 deletions.
189 changes: 189 additions & 0 deletions charts/yurt-manager/crds/apps.openyurt.io_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,195 @@ spec:
type: object
type: object
served: true
storage: false
subresources:
status: {}
- additionalPrinterColumns:
- description: The type of nodepool
jsonPath: .spec.type
name: Type
type: string
- description: The number of ready nodes in the pool
jsonPath: .status.readyNodeNum
name: ReadyNodes
type: integer
- jsonPath: .status.unreadyNodeNum
name: NotReadyNodes
type: integer
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1beta2
schema:
openAPIV3Schema:
description: NodePool is the Schema for the nodepools 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:
description: NodePoolSpec defines the desired state of NodePool
properties:
annotations:
additionalProperties:
type: string
description: |-
If specified, the Annotations will be added to all nodes.
NOTE: existing labels with samy keys on the nodes will be overwritten.
type: object
hostNetwork:
description: |-
HostNetwork is used to specify that cni components(like flannel)
will not be installed on the nodes of this NodePool.
This means all pods on the nodes of this NodePool will use
HostNetwork and share network namespace with host machine.
type: boolean
interConnectivity:
description: |-
InterConnectivity represents all nodes in the NodePool can access with each other
through Layer 2 or Layer 3 network or not. If the field is true,
nodepool-level list/watch requests reuse can be applied for this nodepool.
otherwise, only node-level list/watch requests reuse can be applied for the nodepool.
This field cannot be changed after creation.
type: boolean
labels:
additionalProperties:
type: string
description: |-
If specified, the Labels will be added to all nodes.
NOTE: existing labels with samy keys on the nodes will be overwritten.
type: object
leaderElectionStrategy:
description: |-
LeaderElectionStrategy represents the policy how to elect a leader Yurthub in a nodepool.
random: select one ready node as leader at random.
mark: select one ready node as leader from nodes that are specified by labelselector.
More strategies will be supported according to user's new requirements.
type: string
leaderNodeLabelSelector:
additionalProperties:
type: string
description: |-
LeaderNodeLabelSelector is used only when LeaderElectionStrategy is mark. leader Yurhub will be
elected from nodes that filtered by this label selector.
type: object
poolScopeMetadata:
description: |-
PoolScopeMetadata is used for specifying resources which will be shared in the nodepool.
And it is supported to modify dynamically. and the default value is v1.Service and discovery.Endpointslice.
items:
description: |-
GroupVersionKind unambiguously identifies a kind. It doesn't anonymously include GroupVersion
to avoid automatic coercion. It doesn't use a GroupVersion to avoid custom marshalling
properties:
group:
type: string
kind:
type: string
version:
type: string
required:
- group
- kind
- version
type: object
type: array
taints:
description: If specified, the Taints will be added to all nodes.
items:
description: |-
The node this Taint is attached to has the "effect" on
any pod that does not tolerate the Taint.
properties:
effect:
description: |-
Required. The effect of the taint on pods
that do not tolerate the taint.
Valid effects are NoSchedule, PreferNoSchedule and NoExecute.
type: string
key:
description: Required. The taint key to be applied to a node.
type: string
timeAdded:
description: |-
TimeAdded represents the time at which the taint was added.
It is only written for NoExecute taints.
format: date-time
type: string
value:
description: The taint value corresponding to the taint key.
type: string
required:
- effect
- key
type: object
type: array
type:
description: The type of the NodePool
type: string
type: object
status:
description: NodePoolStatus defines the observed state of NodePool
properties:
conditions:
description: |-
Conditions represents the latest available observations of a NodePool's
current state that includes LeaderHubElection status.
items:
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status to another.
format: date-time
type: string
message:
description: A human readable message indicating details about the transition.
type: string
reason:
description: The 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 NodePool condition.
type: string
type: object
type: array
leaderEndpoints:
description: LeaderEndpoints is used for storing the address of Leader Yurthub.
items:
type: string
type: array
nodes:
description: The list of nodes' names in the pool
items:
type: string
type: array
readyNodeNum:
description: Total number of ready nodes in the pool.
format: int32
type: integer
unreadyNodeNum:
description: Total number of unready nodes in the pool.
format: int32
type: integer
type: object
type: object
served: true
storage: true
subresources:
status: {}
Expand Down
16 changes: 8 additions & 8 deletions charts/yurt-manager/templates/yurt-manager-auto-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1500,19 +1500,19 @@ webhooks:
sideEffects: None
- admissionReviewVersions:
- v1
- v1beta1
- v1beta2
clientConfig:
service:
name: yurt-manager-webhook-service
namespace: {{ .Release.Namespace }}
path: /mutate-apps-openyurt-io-v1beta1-nodepool
path: /mutate-apps-openyurt-io-v1beta2-nodepool
failurePolicy: Fail
name: m.v1beta1.nodepool.kb.io
name: m.v1beta2.nodepool.kb.io
rules:
- apiGroups:
- apps.openyurt.io
apiVersions:
- v1beta1
- v1beta2
operations:
- CREATE
resources:
Expand Down Expand Up @@ -1690,19 +1690,19 @@ webhooks:
sideEffects: None
- admissionReviewVersions:
- v1
- v1beta1
- v1beta2
clientConfig:
service:
name: yurt-manager-webhook-service
namespace: {{ .Release.Namespace }}
path: /validate-apps-openyurt-io-v1beta1-nodepool
path: /validate-apps-openyurt-io-v1beta2-nodepool
failurePolicy: Fail
name: v.v1beta1.nodepool.kb.io
name: v.v1beta2.nodepool.kb.io
rules:
- apiGroups:
- apps.openyurt.io
apiVersions:
- v1beta1
- v1beta2
operations:
- CREATE
- UPDATE
Expand Down
26 changes: 26 additions & 0 deletions pkg/apis/addtoscheme_apps_v1beta2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2023 The OpenYurt Authors.
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package apis

import (
version "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta2"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, version.SchemeBuilder.AddToScheme)
}
12 changes: 8 additions & 4 deletions pkg/apis/apps/v1alpha1/nodepool_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import (
"sigs.k8s.io/controller-runtime/pkg/conversion"

"github.com/openyurtio/openyurt/pkg/apis/apps"
"github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1"
"github.com/openyurtio/openyurt/pkg/apis/apps/v1beta2"
)

func (src *NodePool) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta1.NodePool)
dst := dstRaw.(*v1beta2.NodePool)

dst.ObjectMeta = src.ObjectMeta

dst.Spec.Type = v1beta1.NodePoolType(src.Spec.Type)
dst.Spec.Type = v1beta2.NodePoolType(src.Spec.Type)
dst.Spec.Labels = src.Spec.Labels
dst.Spec.Annotations = src.Spec.Annotations
dst.Spec.Taints = src.Spec.Taints
Expand All @@ -43,13 +43,17 @@ func (src *NodePool) ConvertTo(dstRaw conversion.Hub) error {
dst.Status.UnreadyNodeNum = src.Status.UnreadyNodeNum
dst.Status.Nodes = src.Status.Nodes

// Set interconnectivity to false which will not use leader election strategy or reuse list/watch events
dst.Spec.InterConnectivity = false
dst.Spec.LeaderElectionStrategy = string(v1beta2.ElectionStrategyRandom)

klog.V(4).Infof("convert from v1alpha1 to v1beta1 for nodepool %s", dst.Name)

return nil
}

func (dst *NodePool) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta1.NodePool)
src := srcRaw.(*v1beta2.NodePool)

dst.ObjectMeta = src.ObjectMeta

Expand Down
66 changes: 59 additions & 7 deletions pkg/apis/apps/v1beta1/nodepool_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,63 @@ limitations under the License.

package v1beta1

/*
Implementing the hub method is pretty easy -- we just have to add an empty
method called `Hub()` to serve as a
[marker](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/conversion?tab=doc#Hub).
*/
import (
"strings"

"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/conversion"

"github.com/openyurtio/openyurt/pkg/apis/apps"
"github.com/openyurtio/openyurt/pkg/apis/apps/v1beta2"
)

func (src *NodePool) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta2.NodePool)

dst.ObjectMeta = src.ObjectMeta

dst.Spec.Type = v1beta2.NodePoolType(src.Spec.Type)
dst.Spec.Labels = src.Spec.Labels
dst.Spec.Annotations = src.Spec.Annotations
dst.Spec.Taints = src.Spec.Taints
if strings.EqualFold(src.Annotations[apps.NodePoolHostNetworkLabel], "true") {
dst.Spec.HostNetwork = true
}

dst.Status.ReadyNodeNum = src.Status.ReadyNodeNum
dst.Status.UnreadyNodeNum = src.Status.UnreadyNodeNum
dst.Status.Nodes = src.Status.Nodes

// Set interconnectivity to false which will not use leader election strategy or reuse list/watch events
dst.Spec.InterConnectivity = false
dst.Spec.LeaderElectionStrategy = string(v1beta2.ElectionStrategyRandom)

klog.V(4).Infof("convert from v1beta to v1beta2 for nodepool %s", dst.Name)

return nil
}

func (dst *NodePool) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta2.NodePool)

dst.ObjectMeta = src.ObjectMeta

dst.Spec.Type = NodePoolType(src.Spec.Type)
dst.Spec.Labels = src.Spec.Labels
dst.Spec.Annotations = src.Spec.Annotations
dst.Spec.Taints = src.Spec.Taints

dst.Status.ReadyNodeNum = src.Status.ReadyNodeNum
dst.Status.UnreadyNodeNum = src.Status.UnreadyNodeNum
dst.Status.Nodes = src.Status.Nodes

if src.Spec.HostNetwork {
if dst.Annotations == nil {
dst.Annotations = make(map[string]string)
}
dst.Annotations[apps.NodePoolHostNetworkLabel] = "true"
}

// Hub marks this type as a conversion hub.
func (*NodePool) Hub() {}
klog.V(4).Infof("convert from v1beta2 to v1beta1 for nodepool %s", dst.Name)
return nil
}
1 change: 0 additions & 1 deletion pkg/apis/apps/v1beta1/nodepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ type NodePoolStatus struct {
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +genclient:nonNamespaced
// +kubebuilder:storageversion

// NodePool is the Schema for the nodepools API
type NodePool struct {
Expand Down
Loading

0 comments on commit 470292f

Please sign in to comment.