options.go 3.2 KB
Newer Older
Z
zryfish 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
Copyright 2020 KubeSphere 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.
*/

Z
zryfish 已提交
17 18
package multicluster

19 20 21 22 23 24 25
import (
	"time"

	"github.com/spf13/pflag"
)

const DefaultResyncPeriod = time.Duration(120) * time.Second
Z
zryfish 已提交
26 27 28 29 30

type Options struct {
	// Enable
	Enable           bool `json:"enable"`
	EnableFederation bool `json:"enableFederation,omitempty"`
31 32 33 34 35 36 37 38 39 40 41 42 43 44

	// ProxyPublishService is the service name of multicluster component tower.
	//   If this field provided, apiserver going to use the ingress.ip of this service.
	// This field will be used when generating agent deployment yaml for joining clusters.
	ProxyPublishService string `json:"proxyPublishService,omitempty"`

	// ProxyPublishAddress is the public address of tower for all cluster agents.
	//   This field takes precedence over field ProxyPublishService.
	// If both field ProxyPublishService and ProxyPublishAddress are empty, apiserver will
	// return 404 Not Found for all cluster agent yaml requests.
	ProxyPublishAddress string `json:"proxyPublishAddress,omitempty"`

	// AgentImage is the image used when generating deployment for all cluster agents.
	AgentImage string `json:"agentImage,omitempty"`
45 46 47

	// ClusterControllerResyncSecond is the resync period used by cluster controller.
	ClusterControllerResyncSecond time.Duration `json:"clusterControllerResyncSecond,omitempty" yaml:"clusterControllerResyncSecond"`
Z
zryfish 已提交
48 49 50 51 52
}

// NewOptions() returns a default nil options
func NewOptions() *Options {
	return &Options{
53 54 55 56 57 58
		Enable:                        false,
		EnableFederation:              false,
		ProxyPublishAddress:           "",
		ProxyPublishService:           "",
		AgentImage:                    "kubesphere/tower:v1.0",
		ClusterControllerResyncSecond: DefaultResyncPeriod,
Z
zryfish 已提交
59 60 61 62 63 64 65 66 67 68
	}
}

func (o *Options) Validate() []error {
	return nil
}

func (o *Options) AddFlags(fs *pflag.FlagSet, s *Options) {
	fs.BoolVar(&o.Enable, "multiple-clusters", s.Enable, ""+
		"This field instructs KubeSphere to enter multiple-cluster mode or not.")
69 70 71 72 73 74 75

	fs.StringVar(&o.ProxyPublishService, "proxy-publish-service", s.ProxyPublishService, ""+
		"Service name of tower. APIServer will use its ingress address as proxy publish address."+
		"For example, tower.kubesphere-system.svc.")

	fs.StringVar(&o.ProxyPublishAddress, "proxy-publish-address", s.ProxyPublishAddress, ""+
		"Public address of tower, APIServer will use this field as proxy publish address. This field "+
Z
zryfish 已提交
76
		"takes precedence over field proxy-publish-service. For example, http://139.198.121.121:8080.")
77

Z
zryfish 已提交
78
	fs.StringVar(&o.AgentImage, "agent-image", s.AgentImage, ""+
79
		"This field is used when generating deployment yaml for agent.")
80 81 82

	fs.DurationVar(&o.ClusterControllerResyncSecond, "cluster-controller-resync-second", s.ClusterControllerResyncSecond,
		"Cluster controller resync second to sync cluster resource.")
Z
zryfish 已提交
83
}