Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade nodepool crd to v1beta2 #2266

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
rambohe-ch marked this conversation as resolved.
Show resolved Hide resolved
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 @@
"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)

Check warning on line 30 in pkg/apis/apps/v1alpha1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1alpha1/nodepool_conversion.go#L30

Added line #L30 was not covered by tests

dst.ObjectMeta = src.ObjectMeta

dst.Spec.Type = v1beta1.NodePoolType(src.Spec.Type)
dst.Spec.Type = v1beta2.NodePoolType(src.Spec.Type)

Check warning on line 34 in pkg/apis/apps/v1alpha1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1alpha1/nodepool_conversion.go#L34

Added line #L34 was not covered by tests
dst.Spec.Labels = src.Spec.Labels
dst.Spec.Annotations = src.Spec.Annotations
dst.Spec.Taints = src.Spec.Taints
Expand All @@ -43,13 +43,17 @@
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)

Check warning on line 48 in pkg/apis/apps/v1alpha1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1alpha1/nodepool_conversion.go#L47-L48

Added lines #L47 - L48 were not covered by tests

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)

Check warning on line 56 in pkg/apis/apps/v1alpha1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1alpha1/nodepool_conversion.go#L56

Added line #L56 was not covered by tests

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 @@

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)

Check warning on line 30 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L29-L30

Added lines #L29 - L30 were not covered by tests

dst.ObjectMeta = src.ObjectMeta

Check warning on line 32 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L32

Added line #L32 was not covered by tests

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

Check warning on line 39 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L34-L39

Added lines #L34 - L39 were not covered by tests
}

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

Check warning on line 44 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L42-L44

Added lines #L42 - L44 were not covered by tests

// 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)

Check warning on line 48 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L47-L48

Added lines #L47 - L48 were not covered by tests

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

Check warning on line 50 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L50

Added line #L50 was not covered by tests

return nil

Check warning on line 52 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L52

Added line #L52 was not covered by tests
}

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

Check warning on line 56 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L55-L56

Added lines #L55 - L56 were not covered by tests

dst.ObjectMeta = src.ObjectMeta

Check warning on line 58 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L58

Added line #L58 was not covered by tests

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

Check warning on line 63 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L60-L63

Added lines #L60 - L63 were not covered by tests

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

Check warning on line 67 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L65-L67

Added lines #L65 - L67 were not covered by tests

if src.Spec.HostNetwork {
if dst.Annotations == nil {
dst.Annotations = make(map[string]string)

Check warning on line 71 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L69-L71

Added lines #L69 - L71 were not covered by tests
}
dst.Annotations[apps.NodePoolHostNetworkLabel] = "true"

Check warning on line 73 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L73

Added line #L73 was not covered by tests
}

// 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

Check warning on line 77 in pkg/apis/apps/v1beta1/nodepool_conversion.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/apps/v1beta1/nodepool_conversion.go#L76-L77

Added lines #L76 - L77 were not covered by tests
}
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
Loading