-
Notifications
You must be signed in to change notification settings - Fork 408
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
) | ||
|
||
// Provider signifies the provider type | ||
|
@@ -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 | ||
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think use tag There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
@@ -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 { | ||
|
@@ -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 { | ||
|
@@ -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) | ||
|
@@ -353,6 +380,18 @@ func (co *ConvertOptions) RunConvert() (err error) { | |
if err != nil { | ||
return err | ||
} | ||
|
||
//8. deploy the yurtappmanager if required | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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), | ||
|
@@ -377,6 +416,84 @@ func (co *ConvertOptions) RunConvert() (err error) { | |
return | ||
} | ||
|
||
func deployYurtAppManager( | ||
client *kubernetes.Clientset, | ||
cloudNodes []string, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like the func There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
There was a problem hiding this comment.
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 modifiedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified