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

add StaticPod CRD and controller #1261

Merged
merged 11 commits into from
Apr 13, 2023
207 changes: 206 additions & 1 deletion charts/openyurt/templates/yurt-manager-auto-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,130 @@ status:
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
creationTimestamp: null
name: staticpods.apps.openyurt.io
spec:
group: apps.openyurt.io
names:
kind: StaticPod
listKind: StaticPodList
plural: staticpods
shortNames:
- sp
singular: staticpod
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: CreationTimestamp is a timestamp representing the server time when
this object was created. It is not guaranteed to be set in happens-before
order across separate operations. Clients may not set this value. It is represented
in RFC3339 form and is in UTC.
jsonPath: .metadata.creationTimestamp
name: AGE
type: date
- description: The total number of static pods
jsonPath: .status.totalNumber
name: TotalNumber
type: integer
- description: The number of ready static pods
jsonPath: .status.readyNumber
name: ReadyNumber
type: integer
- description: The number of static pods that have been upgraded
jsonPath: .status.upgradedNumber
name: UpgradedNumber
type: integer
name: v1alpha1
schema:
openAPIV3Schema:
description: StaticPod is the Schema for the staticpods 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: StaticPodSpec defines the desired state of StaticPod
properties:
revisionHistoryLimit:
description: The number of old history to retain to allow rollback.
Defaults to 10.
format: int32
type: integer
staticPodManifest:
description: StaticPodManifest indicates the Static Pod desired to
be upgraded. The corresponding manifest file name is `StaticPodManifest.yaml`.
type: string
template:
description: An object that describes the desired upgrade static pod.
x-kubernetes-preserve-unknown-fields: true
upgradeStrategy:
description: An upgrade strategy to replace existing static pods with
new ones.
properties:
maxUnavailable:
anyOf:
- type: integer
- type: string
description: Auto upgrade config params. Present only if type
= "auto".
x-kubernetes-int-or-string: true
type:
description: Type of Static Pod upgrade. Can be "auto" or "ota".
type: string
type: object
type: object
status:
description: StaticPodStatus defines the observed state of StaticPod
properties:
observedGeneration:
description: The most recent generation observed by the static pod
controller.
format: int64
type: integer
readyNumber:
description: The number of ready static pods.
format: int32
type: integer
totalNumber:
description: The total number of nodes that are running the static
pod.
format: int32
type: integer
upgradedNumber:
description: The number of nodes that are running updated static pod.
format: int32
type: integer
required:
- readyNumber
- totalNumber
- upgradedNumber
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
Expand Down Expand Up @@ -580,6 +704,32 @@ rules:
- get
- patch
- update
- apiGroups:
- apps.openyurt.io
resources:
- staticpods
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps.openyurt.io
resources:
- staticpods/finalizers
verbs:
- update
- apiGroups:
- apps.openyurt.io
resources:
- staticpods/status
verbs:
- get
- patch
- update
- apiGroups:
- certificates.k8s.io
resources:
Expand Down Expand Up @@ -616,6 +766,18 @@ rules:
- patch
- update
- watch
- apiGroups:
- ""
resources:
- configmaps
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -764,6 +926,27 @@ webhooks:
resources:
- nodepools
sideEffects: None
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: webhook-service
namespace: kube-system
path: /mutate-apps-openyurt-io-v1alpha1-staticpod
failurePolicy: Fail
name: mutate.apps.v1alpha1.staticpod.openyurt.io
rules:
- apiGroups:
- apps.openyurt.io
apiVersions:
- v1alpha1
operations:
- CREATE
- UPDATE
resources:
- staticpods
sideEffects: None
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down Expand Up @@ -815,6 +998,28 @@ webhooks:
sideEffects: None
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: webhook-service
namespace: kube-system
path: /validate-apps-openyurt-io-v1alpha1-staticpod
failurePolicy: Fail
name: validate.apps.v1alpha1.staticpod.openyurt.io
rules:
- apiGroups:
- apps.openyurt.io
apiVersions:
- v1alpha1
operations:
- CREATE
- UPDATE
resources:
- staticpods
sideEffects: None
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: webhook-service
Expand All @@ -824,7 +1029,7 @@ webhooks:
name: validate.core.v1.pod.openyurt.io
rules:
- apiGroups:
- ""
- core.openyurt.io
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the group of pod is "" instead of core.openyurt.io

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

apiVersions:
- v1
operations:
Expand Down
20 changes: 13 additions & 7 deletions cmd/yurt-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ import (

// YurtManagerOptions is the main context object for the yurt-manager.
type YurtManagerOptions struct {
Generic *GenericOptions
NodePoolController *NodePoolControllerOptions
GatewayController *GatewayControllerOptions
Generic *GenericOptions
NodePoolController *NodePoolControllerOptions
GatewayController *GatewayControllerOptions
StaticPodController *StaticPodControllerOptions
}

// NewYurtManagerOptions creates a new YurtManagerOptions with a default config.
func NewYurtManagerOptions() (*YurtManagerOptions, error) {

s := YurtManagerOptions{
Generic: NewGenericOptions(),
NodePoolController: NewNodePoolControllerOptions(),
GatewayController: NewGatewayControllerOptions(),
Generic: NewGenericOptions(),
NodePoolController: NewNodePoolControllerOptions(),
GatewayController: NewGatewayControllerOptions(),
StaticPodController: NewStaticPodControllerOptions(),
}

return &s, nil
Expand All @@ -46,7 +48,7 @@ func (y *YurtManagerOptions) Flags() cliflag.NamedFlagSets {
y.Generic.AddFlags(fss.FlagSet("generic"))
y.NodePoolController.AddFlags(fss.FlagSet("nodepool controller"))
y.GatewayController.AddFlags(fss.FlagSet("gateway controller"))

y.StaticPodController.AddFlags(fss.FlagSet("staticpod controller"))
// Please Add Other controller flags @kadisi

return fss
Expand All @@ -58,6 +60,7 @@ func (y *YurtManagerOptions) Validate() error {
errs = append(errs, y.Generic.Validate()...)
errs = append(errs, y.NodePoolController.Validate()...)
errs = append(errs, y.GatewayController.Validate()...)
errs = append(errs, y.StaticPodController.Validate()...)
return utilerrors.NewAggregate(errs)
}

Expand All @@ -69,6 +72,9 @@ func (y *YurtManagerOptions) ApplyTo(c *config.Config) error {
if err := y.NodePoolController.ApplyTo(&c.ComponentConfig.NodePoolController); err != nil {
return err
}
if err := y.StaticPodController.ApplyTo(&c.ComponentConfig.StaticPodController); err != nil {
return err
}
return nil
}

Expand Down
64 changes: 64 additions & 0 deletions cmd/yurt-manager/app/options/staticpodcontroller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
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 options

import (
"github.com/spf13/pflag"

"github.com/openyurtio/openyurt/pkg/controller/staticpod/config"
)

const DefaultUpgradeWorkerImage = "openyurt/node-servant:latest"

type StaticPodControllerOptions struct {
*config.StaticPodControllerConfiguration
}

func NewStaticPodControllerOptions() *StaticPodControllerOptions {
return &StaticPodControllerOptions{
&config.StaticPodControllerConfiguration{
UpgradeWorkerImage: DefaultUpgradeWorkerImage,
},
}
}

// AddFlags adds flags related to staticpod for yurt-manager to the specified FlagSet.
func (o *StaticPodControllerOptions) AddFlags(fs *pflag.FlagSet) {
if o == nil {
return
}

fs.StringVar(&o.UpgradeWorkerImage, "upgrade-worker-image", o.UpgradeWorkerImage, "Specify the worker pod image used for static pod upgrade.")
}

// ApplyTo fills up staticpod config with options.
func (o *StaticPodControllerOptions) ApplyTo(cfg *config.StaticPodControllerConfiguration) error {
if o == nil {
return nil
}
cfg.UpgradeWorkerImage = o.UpgradeWorkerImage
return nil
}

// Validate checks validation of StaticPodControllerOptions.
func (o *StaticPodControllerOptions) Validate() []error {
if o == nil {
return nil
}
errs := []error{}
return errs
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
k8s.io/api v0.22.3
k8s.io/apimachinery v0.22.3
k8s.io/apiserver v0.22.3
k8s.io/cli-runtime v0.22.3
k8s.io/client-go v0.22.3
k8s.io/cluster-bootstrap v0.22.3
k8s.io/component-base v0.22.3
Expand All @@ -58,7 +59,6 @@ require (
github.com/russross/blackfriday v1.5.2 // indirect
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
k8s.io/cli-runtime v0.22.3
sigs.k8s.io/kustomize/api v0.8.11 // indirect
sigs.k8s.io/kustomize/kyaml v0.11.0 // indirect
)
Expand Down
Loading