Skip to content

Commit

Permalink
add parameter upgrade-worker-image to specify image of worker pod
Browse files Browse the repository at this point in the history
Signed-off-by: hxcGit <[email protected]>
  • Loading branch information
xavier-hou committed Mar 31, 2023
1 parent adc8d6f commit 6e16954
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions cmd/yurt-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,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
18 changes: 11 additions & 7 deletions cmd/yurt-manager/app/options/staticpodcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,35 @@ import (
"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{},
&config.StaticPodControllerConfiguration{
UpgradeWorkerImage: DefaultUpgradeWorkerImage,
},
}
}

// AddFlags adds flags related to nodepool for yurt-manager to the specified FlagSet.
func (n *StaticPodControllerOptions) AddFlags(fs *pflag.FlagSet) {
if n == nil {
// 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.BoolVar(&n.CreateDefaultPool, "create-default-pool", n.CreateDefaultPool, "Create default cloud/edge pools if indicated.")
fs.StringVar(&o.UpgradeWorkerImage, "upgrade-worker-image", o.UpgradeWorkerImage, "Specify the worker pod image used for static pod upgrade.")
}

// ApplyTo fills up nodepool config with options.
// 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
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/staticpod/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ package config

// StaticPodControllerConfiguration contains elements describing GatewayController.
type StaticPodControllerConfiguration struct {
// UpgradeWorkerImage specify the image used to execute the upgrade task
UpgradeWorkerImage string
}
15 changes: 7 additions & 8 deletions pkg/controller/staticpod/staticpod_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const (
// UpgradeWorkerPodPrefix is the name prefix of worker pod which used for static pod upgrade
UpgradeWorkerPodPrefix = "yurt-static-pod-upgrade-worker-"
UpgradeWorkerContainerName = "upgrade-worker"
UpgradeWorkerImage = "openyurt/yurt-static-pod-upgrade:latest"

ArgTmpl = "/usr/local/bin/yurt-static-pod-upgrade --manifest=%s --mode=%s"
)
Expand All @@ -83,8 +82,9 @@ const (
// Fields need be set
// 1. name of worker pod: `yurt-static-pod-upgrade-worker-node-hash`
// 2. node of worker pod
// 3. annotation `openyurt.io/static-pod-hash`
// 4. the corresponding configmap
// 3. image of worker pod, default is "openyurt/node-servant:latest"
// 4. annotation `openyurt.io/static-pod-hash`
// 5. the corresponding configmap
var (
upgradeWorker = &corev1.Pod{
Spec: corev1.PodSpec{
Expand All @@ -108,7 +108,6 @@ var (
SecurityContext: &corev1.SecurityContext{
Privileged: &True,
},
Image: UpgradeWorkerImage,
}},
Volumes: []corev1.Volume{{
Name: hostPathVolumeName,
Expand Down Expand Up @@ -521,7 +520,7 @@ func (r *ReconcileStaticPod) autoUpgrade(instance *appsv1alpha1.StaticPod, infos
}

readyUpgradeWaitingNodes = readyUpgradeWaitingNodes[:max]
if err := createUpgradeWorker(r.Client, instance, readyUpgradeWaitingNodes, hash, string(appsv1alpha1.AutoStaticPodUpgradeStrategyType)); err != nil {
if err := createUpgradeWorker(r.Client, instance, readyUpgradeWaitingNodes, hash, string(appsv1alpha1.AutoStaticPodUpgradeStrategyType), r.Configration.UpgradeWorkerImage); err != nil {
return err
}
return nil
Expand All @@ -548,7 +547,7 @@ func (r *ReconcileStaticPod) otaUpgrade(instance *appsv1alpha1.StaticPod, infos

// Create worker pod to issue the latest manifest to ready node
readyUpgradeWaitingNodes := upgradeinfo.OTAReadyUpgradeWaitingNodes(infos, hash)
if err := createUpgradeWorker(r.Client, instance, readyUpgradeWaitingNodes, hash, string(appsv1alpha1.OTAStaticPodUpgradeStrategyType)); err != nil {
if err := createUpgradeWorker(r.Client, instance, readyUpgradeWaitingNodes, hash, string(appsv1alpha1.OTAStaticPodUpgradeStrategyType), r.Configration.UpgradeWorkerImage); err != nil {
return err
}

Expand Down Expand Up @@ -590,7 +589,7 @@ func (r *ReconcileStaticPod) removeUnusedPods(pods []*corev1.Pod) error {
}

// createUpgradeWorker creates static pod upgrade worker to the given nodes
func createUpgradeWorker(c client.Client, instance *appsv1alpha1.StaticPod, nodes []string, hash, mode string) error {
func createUpgradeWorker(c client.Client, instance *appsv1alpha1.StaticPod, nodes []string, hash, mode, img string) error {
for _, node := range nodes {
pod := upgradeWorker.DeepCopy()
pod.Name = UpgradeWorkerPodPrefix + util.Hyphen(node, hash)
Expand All @@ -608,7 +607,7 @@ func createUpgradeWorker(c client.Client, instance *appsv1alpha1.StaticPod, node
},
})
pod.Spec.Containers[0].Args = []string{fmt.Sprintf(ArgTmpl, instance.Spec.StaticPodManifest, mode)}

pod.Spec.Containers[0].Image = img
if err := controllerutil.SetControllerReference(instance, pod, c.Scheme()); err != nil {
return err
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/webhook/staticpod/v1alpha1/staticpod_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha1

import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand All @@ -28,9 +27,6 @@ import (

// SetupWebhookWithManager sets up Cluster webhooks. mutate path, validatepath, error
func (webhook *StaticPodHandler) SetupWebhookWithManager(mgr ctrl.Manager) (string, string, error) {
// init
webhook.Client = mgr.GetClient()

gvk, err := apiutil.GVKForObject(&v1alpha1.StaticPod{}, mgr.GetScheme())
if err != nil {
return "", "", err
Expand All @@ -49,7 +45,6 @@ func (webhook *StaticPodHandler) SetupWebhookWithManager(mgr ctrl.Manager) (stri

// Cluster implements a validating and defaulting webhook for Cluster.
type StaticPodHandler struct {
Client client.Client
}

var _ webhook.CustomDefaulter = &StaticPodHandler{}
Expand Down

0 comments on commit 6e16954

Please sign in to comment.