Skip to content

Commit

Permalink
add tunnelServerAddress (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamzhoul authored Sep 26, 2021
1 parent 07c3409 commit c50a8d0
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 51 deletions.
12 changes: 11 additions & 1 deletion pkg/yurtctl/cmd/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type ConvertOptions struct {
YurtControllerManagerImage string
YurctlServantImage string
YurttunnelServerImage string
YurttunnelServerAddress string
YurttunnelAgentImage string
PodMainfestPath string
KubeadmConfPath string
Expand Down Expand Up @@ -129,6 +130,9 @@ func NewConvertCmd() *cobra.Command {
cmd.Flags().String("yurt-tunnel-server-image",
"openyurt/yurt-tunnel-server:latest",
"The yurt-tunnel-server image.")
cmd.Flags().String("yurt-tunnel-server-address",
"",
"The yurt-tunnel-server address.")
cmd.Flags().String("yurt-tunnel-agent-image",
"openyurt/yurt-tunnel-agent:latest",
"The yurt-tunnel-agent image.")
Expand Down Expand Up @@ -206,6 +210,12 @@ func (co *ConvertOptions) Complete(flags *pflag.FlagSet) error {
}
co.YurttunnelServerImage = ytsi

ytsa, err := flags.GetString("yurt-tunnel-server-address")
if err != nil {
return err
}
co.YurttunnelServerAddress = ytsa

ytai, err := flags.GetString("yurt-tunnel-agent-image")
if err != nil {
return err
Expand Down Expand Up @@ -351,7 +361,7 @@ func (co *ConvertOptions) RunConvert() (err error) {
klog.Info("yurt-tunnel-server is deployed")
// we will deploy yurt-tunnel-agent on every edge node
if err = kubeutil.DeployYurttunnelAgent(co.clientSet,
edgeNodeNames,
co.YurttunnelServerAddress,
co.YurttunnelAgentImage); err != nil {
err = fmt.Errorf("fail to deploy the yurt-tunnel-agent: %s", err)
return
Expand Down
102 changes: 56 additions & 46 deletions pkg/yurtctl/cmd/yurtinit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,20 @@ var (
// Please note that this structure includes the public kubeadm config API, but only a subset of the options
// supported by this api will be exposed as a flag.
type initOptions struct {
cfgPath string
kubeconfigDir string
kubeconfigPath string
featureGatesString string
ignorePreflightErrors []string
bto *options.BootstrapTokenOptions
externalInitCfg *kubeadmapiv1beta2.InitConfiguration
externalClusterCfg *kubeadmapiv1beta2.ClusterConfiguration
kustomizeDir string
installCNIFile string
isConvertOpenYurtCluster bool
openyurtImageRegistry string
openyurtVersion string
cfgPath string
kubeconfigDir string
kubeconfigPath string
featureGatesString string
ignorePreflightErrors []string
bto *options.BootstrapTokenOptions
externalInitCfg *kubeadmapiv1beta2.InitConfiguration
externalClusterCfg *kubeadmapiv1beta2.ClusterConfiguration
kustomizeDir string
installCNIFile string
isConvertOpenYurtCluster bool
openyurtImageRegistry string
openyurtVersion string
openyurtTunnelServerAddress string
}

// compile-time assert that the local data object satisfies the phases data interface.
Expand All @@ -106,24 +107,25 @@ var _ yurtphase.YurtInitData = &initData{}
// initData defines all the runtime information used when running the kubeadm init workflow;
// this data is shared across all the phases that are included in the workflow.
type initData struct {
cfg *kubeadmapi.InitConfiguration
skipTokenPrint bool
dryRun bool
kubeconfigDir string
kubeconfigPath string
ignorePreflightErrors sets.String
certificatesDir string
dryRunDir string
externalCA bool
client clientset.Interface
outputWriter io.Writer
uploadCerts bool
skipCertificateKeyPrint bool
kustomizeDir string
cniFileName string
isConvertOpenYurtCluster bool
openyurtImageRegistry string
openyurtVersion string
cfg *kubeadmapi.InitConfiguration
skipTokenPrint bool
dryRun bool
kubeconfigDir string
kubeconfigPath string
ignorePreflightErrors sets.String
certificatesDir string
dryRunDir string
externalCA bool
client clientset.Interface
outputWriter io.Writer
uploadCerts bool
skipCertificateKeyPrint bool
kustomizeDir string
cniFileName string
isConvertOpenYurtCluster bool
openyurtImageRegistry string
openyurtVersion string
openyurtTunnelServerAddress string
}

// NewCmdInit returns "kubeadm init" command.
Expand Down Expand Up @@ -253,6 +255,8 @@ func AddInitOtherFlags(flagSet *flag.FlagSet, initOptions *initOptions) {
"Choose a container registry to pull OpenYurt component images from")
flagSet.StringVar(&initOptions.openyurtVersion, "yurt-version", "",
"Choose a specific OpenYurt version")
flagSet.StringVar(&initOptions.openyurtTunnelServerAddress, "yurt-tunnel-server-address", "",
"Choose an accessible address for tunnelAgent when deployed in an isolated network")
flagSet.StringVar(&initOptions.installCNIFile, "install-cni-file", "",
"Configure install cni yaml file.")
flagSet.BoolVar(
Expand Down Expand Up @@ -362,21 +366,22 @@ func newInitData(cmd *cobra.Command, args []string, options *initOptions, out io
}

return &initData{
cfg: cfg,
certificatesDir: cfg.CertificatesDir,
skipTokenPrint: false,
kubeconfigDir: options.kubeconfigDir,
kubeconfigPath: options.kubeconfigPath,
ignorePreflightErrors: ignorePreflightErrorsSet,
externalCA: externalCA,
outputWriter: out,
uploadCerts: false,
skipCertificateKeyPrint: false,
kustomizeDir: options.kustomizeDir,
isConvertOpenYurtCluster: options.isConvertOpenYurtCluster,
openyurtVersion: options.openyurtVersion,
cniFileName: options.installCNIFile,
openyurtImageRegistry: options.openyurtImageRegistry,
cfg: cfg,
certificatesDir: cfg.CertificatesDir,
skipTokenPrint: false,
kubeconfigDir: options.kubeconfigDir,
kubeconfigPath: options.kubeconfigPath,
ignorePreflightErrors: ignorePreflightErrorsSet,
externalCA: externalCA,
outputWriter: out,
uploadCerts: false,
skipCertificateKeyPrint: false,
kustomizeDir: options.kustomizeDir,
isConvertOpenYurtCluster: options.isConvertOpenYurtCluster,
openyurtVersion: options.openyurtVersion,
cniFileName: options.installCNIFile,
openyurtImageRegistry: options.openyurtImageRegistry,
openyurtTunnelServerAddress: options.openyurtTunnelServerAddress,
}, nil
}

Expand Down Expand Up @@ -495,6 +500,11 @@ func (d *initData) CNIFileName() string {
return d.cniFileName
}

// YurtTunnelAddress return the openyurtTunnelServerAddress
func (d *initData) YurtTunnelAddress() string {
return d.openyurtTunnelServerAddress
}

// Client returns a Kubernetes client to be used by kubeadm.
// This function is implemented as a singleton, thus avoiding to recreate the client when it is used by different phases.
// Important. This function must be called after the admin.conf kubeconfig file is created.
Expand Down
3 changes: 2 additions & 1 deletion pkg/yurtctl/cmd/yurtinit/phases/install_yurt_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func runInstallYurtAddons(c workflow.RunData) error {
}
imageRegistry := data.OpenYurtImageRegistry()
version := data.OpenYurtVersion()
tunnelServerAddress := data.YurtTunnelAddress()

if len(imageRegistry) == 0 {
imageRegistry = YurtContants.DefaultOpenYurtImageRegistry
Expand All @@ -77,7 +78,7 @@ func runInstallYurtAddons(c workflow.RunData) error {
if err := kubeutil.DeployYurttunnelServer(client, nil, fmt.Sprintf("%s/%s:%s", imageRegistry, YurtContants.YurtTunnelServer, version), runtime.GOARCH); err != nil {
return err
}
if err := kubeutil.DeployYurttunnelAgent(client, nil, fmt.Sprintf("%s/%s:%s", imageRegistry, YurtContants.YurtTunnelAgent, version)); err != nil {
if err := kubeutil.DeployYurttunnelAgent(client, tunnelServerAddress, fmt.Sprintf("%s/%s:%s", imageRegistry, YurtContants.YurtTunnelAgent, version)); err != nil {
return err
}
return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/yurtctl/cmd/yurtinit/phases/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ type YurtInitData interface {
IsConvertYurtCluster() bool
OpenYurtVersion() string
OpenYurtImageRegistry() string
YurtTunnelAddress() string
CNIFileName() string
}
3 changes: 3 additions & 0 deletions pkg/yurtctl/constants/yurt-tunnel-agent-tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ spec:
- yurt-tunnel-agent
args:
- --node-name=$(NODE_NAME)
{{if .tunnelServerAddress }}
- --tunnelserver-addr={{.tunnelServerAddress}}
{{end}}
image: {{.image}}
imagePullPolicy: IfNotPresent
name: yurt-tunnel-agent
Expand Down
1 change: 1 addition & 0 deletions pkg/yurtctl/constants/yurt-tunnel-server-tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ spec:
name: https
- port: 10262
targetPort: 10262
nodePort: 31008
name: tcp
selector:
k8s-app: yurt-tunnel-server
Expand Down
7 changes: 4 additions & 3 deletions pkg/yurtctl/util/kubernetes/apply_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,15 @@ func DeployYurttunnelServer(

func DeployYurttunnelAgent(
client *kubernetes.Clientset,
tunnelAgentNodes []string,
tunnelServerAddress string,
yurttunnelAgentImage string) error {
// 1. Deploy the yurt-tunnel-agent DaemonSet
if err := CreateDaemonSetFromYaml(client,
constants.YurttunnelAgentDaemonSet,
map[string]string{
"image": yurttunnelAgentImage,
"edgeWorkerLabel": projectinfo.GetEdgeWorkerLabelKey()}); err != nil {
"image": yurttunnelAgentImage,
"edgeWorkerLabel": projectinfo.GetEdgeWorkerLabelKey(),
"tunnelServerAddress": tunnelServerAddress}); err != nil {
return err
}
return nil
Expand Down

0 comments on commit c50a8d0

Please sign in to comment.