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

New function development -- yurtctl adds parameter enable app manager to control automatic deployment of yurtappmanager. #352

Merged
merged 3 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
117 changes: 117 additions & 0 deletions pkg/yurtctl/cmd/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/openyurtio/openyurt/pkg/yurtctl/lock"
kubeutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/kubernetes"
strutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/strings"
"k8s.io/client-go/dynamic"
Copy link
Member

Choose a reason for hiding this comment

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

import order needs to be modified

Copy link
Member Author

Choose a reason for hiding this comment

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

modified

)

// Provider signifies the provider type
Expand Down Expand Up @@ -73,6 +74,9 @@ type ConvertOptions struct {
KubeadmConfPath string
DeployTunnel bool
kubeConfigPath string
EnableAppManager bool
YurtAppManagerImage string
yurtAppManagerClientSet dynamic.Interface
}

// NewConvertOptions creates a new ConvertOptions
Expand Down Expand Up @@ -132,6 +136,11 @@ func NewConvertCmd() *cobra.Command {
cmd.Flags().String("pod-manifest-path",
"/etc/kubernetes/manifests",
"Path to the directory on edge node containing static pod files.")
cmd.Flags().BoolP("enable-app-manager", "e", false,
"if set, yurtappmanager will be deployed.")
cmd.Flags().String("yurt-app-manager-image",
"openyurt/yurt-app-manager:v0.4.0",
Copy link
Member

Choose a reason for hiding this comment

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

I think use tag latest is better.

Copy link
Member Author

Choose a reason for hiding this comment

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

The latest version image can't be used without updating. Now we all use the version of v0.4.0.

"The yurt-app-manager image.")

return cmd
}
Expand All @@ -154,6 +163,12 @@ func (co *ConvertOptions) Complete(flags *pflag.FlagSet) error {
return err
}
co.DeployTunnel = dt

eam, err := flags.GetBool("enable-app-manager")
if err != nil {
return err
}
co.EnableAppManager = eam

pStr, err := flags.GetString("provider")
if err != nil {
Expand Down Expand Up @@ -196,6 +211,12 @@ func (co *ConvertOptions) Complete(flags *pflag.FlagSet) error {
return err
}
co.YurttunnelAgentImage = ytai

yami, err := flags.GetString("yurt-app-manager-image")
if err != nil {
return err
}
co.YurtAppManagerImage = yami

pmp, err := flags.GetString("pod-manifest-path")
if err != nil {
Expand All @@ -214,6 +235,12 @@ func (co *ConvertOptions) Complete(flags *pflag.FlagSet) error {
if err != nil {
return err
}

// parse kubeconfig and generate the yurtappmanagerclientset
co.yurtAppManagerClientSet, err = kubeutil.GenDynamicClientSet(flags)
if err != nil {
return err
}

// prepare path of cluster kubeconfig file
co.kubeConfigPath, err = kubeutil.PrepareKubeConfigPath(flags)
Expand Down Expand Up @@ -353,6 +380,18 @@ func (co *ConvertOptions) RunConvert() (err error) {
if err != nil {
return err
}

//8. deploy the yurtappmanager if required
Copy link
Member

Choose a reason for hiding this comment

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

The codes before and after "deploy the yurtappmanager" all belong to step7. How about move it behind step6?

Copy link
Member Author

Choose a reason for hiding this comment

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

Step 7 and "deploy the yurtappmanager" are separate processes and have no impact, so I don't think we need to put them before step 7.

if co.EnableAppManager {
if err = deployYurtAppManager(co.clientSet,
co.CloudNodes,
co.YurtAppManagerImage,
co.yurtAppManagerClientSet); err != nil {
err = fmt.Errorf("fail to deploy the yurt-app-manager: %s", err)
return
}
klog.Info("yurt-app-manager is deployed")
}

ctx := map[string]string{
"provider": string(co.Provider),
Expand All @@ -377,6 +416,84 @@ func (co *ConvertOptions) RunConvert() (err error) {
return
}

func deployYurtAppManager(
client *kubernetes.Clientset,
cloudNodes []string,
Copy link
Member

Choose a reason for hiding this comment

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

The parameter cloudNodes is not used and can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a good idea. I found that this parameter was not used at that time.

yurtappmanagerImage string,
yurtAppManagerClient dynamic.Interface) error {

// 1.create the YurtAppManagerCustomResourceDefinition
// 1.1 nodepool
if err := kubeutil.CreateCRDFromYaml(client, yurtAppManagerClient, "",[]byte(constants.YurtAppManagerNodePool)); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

It seems like the func CreateCRDFromYaml is to create a cr. However, it's used to register crd here.

Copy link
Member Author

Choose a reason for hiding this comment

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

register crd

return err
}

// 1.2 uniteddeployment
if err := kubeutil.CreateCRDFromYaml(client, yurtAppManagerClient, "",[]byte(constants.YurtAppManagerUnitedDeployment)); err != nil {
return err
}

// 2. create the YurtAppManagerRole
if err := kubeutil.CreateRoleFromYaml(client, "kube-system",
constants.YurtAppManagerRole); err != nil {
return err
}

// 3. create the ClusterRole
if err := kubeutil.CreateClusterRoleFromYaml(client,
constants.YurtAppManagerClusterRole); err != nil {
return err
}

// 4. create the RoleBinding
if err := kubeutil.CreateRoleBindingFromYaml(client, "kube-system",
constants.YurtAppManagerRolebinding); err != nil {
return err
}

// 5. create the ClusterRoleBinding
if err := kubeutil.CreateClusterRoleBindingFromYaml(client,
constants.YurtAppManagerClusterRolebinding); err != nil {
return err
}

// 6. create the Secret
if err := kubeutil.CreateSecretFromYaml(client, "kube-system",
constants.YurtAppManagerSecret); err != nil {
return err
}

// 7. create the Service
if err := kubeutil.CreateServiceFromYaml(client,
constants.YurtAppManagerService); err != nil {
return err
}

// 8. create the Deployment
if err := kubeutil.CreateDeployFromYaml(client,
"kube-system",
constants.YurtAppManagerDeployment,
map[string]string{
"image": yurtappmanagerImage,
"edgeWorkerLabel": projectinfo.GetEdgeWorkerLabelKey()}); err != nil {
return err
}

// 9. create the YurtAppManagerMutatingWebhookConfiguration
if err := kubeutil.CreateMutatingWebhookConfigurationFromYaml(client,
constants.YurtAppManagerMutatingWebhookConfiguration); err != nil {
return err
}

// 10. create the YurtAppManagerValidatingWebhookConfiguration
if err := kubeutil.CreateValidatingWebhookConfigurationFromYaml(client,
constants.YurtAppManagerValidatingWebhookConfiguration); err != nil {
return err
}

return nil
}

func deployYurttunnelServer(
client *kubernetes.Clientset,
cloudNodes []string,
Expand Down
Loading