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

feat(installer): support upgrade through installer #939

Merged
merged 5 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 1 addition & 1 deletion build/docker/tools/tke-installer/init_installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tailNum=$((tailNum +1))
tail -n +${tailNum} "${me}" >package.tgz || die
tar -zxf package.tgz || die

./install.sh || die
./install.sh $@ || die
cd "${cwd}" || die
exit 0

Expand Down
2 changes: 1 addition & 1 deletion build/docker/tools/tke-installer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function clean_old_data() {
function start_installer() {
echo "Step.5 start tke-installer [doing]"

docker run $OPTIONS "tkestack/tke-installer-${ARCH}:$VERSION"
docker run $OPTIONS "tkestack/tke-installer-${ARCH}:$VERSION" /app/bin/tke-installer $@
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think need duplicate /app/bin/tke-installer again here


echo "Step.5 start tke-installer [ok]"
}
Expand Down
12 changes: 12 additions & 0 deletions cmd/tke-installer/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ type Config struct {
Force bool
SyncProjectsWithNamespaces bool
Replicas int
Upgrade bool
Kubeconfig string
RegistryUsername string
RegistryPassword string
RegistryDomain string
RegistryNamespace string
}

// CreateConfigFromOptions creates a running configuration instance based
Expand All @@ -48,5 +54,11 @@ func CreateConfigFromOptions(serverName string, opts *options.Options) (*Config,
Force: *opts.Force,
SyncProjectsWithNamespaces: *opts.SyncProjectsWithNamespaces,
Replicas: *opts.Replicas,
Upgrade: *opts.Upgrade,
Kubeconfig: *opts.Kubeconfig,
RegistryUsername: *opts.RegistryUsername,
RegistryPassword: *opts.RegistryPassword,
RegistryDomain: *opts.RegistryDomain,
RegistryNamespace: *opts.RegistryNamespace,
}, nil
}
60 changes: 52 additions & 8 deletions cmd/tke-installer/app/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ func (t *TKE) initSteps() {
Func: t.createGlobalCluster,
},
{
Name: "Patch k8s version in cluster info",
Func: t.patchK8sValidVersions,
Name: "Patch platform versions in cluster info",
Func: t.patchPlatformVersion,
},
{
Name: "Write kubeconfig",
Expand Down Expand Up @@ -409,6 +409,15 @@ func (t *TKE) initSteps() {
}...)
}

if t.Para.Config.Registry.ThirdPartyRegistry != nil {
t.steps = append(t.steps, []types.Handler{
{
Name: "Save third party registry info",
Func: t.saveThirdPartyRegistryInfo,
},
}...)
}

t.steps = append(t.steps, []types.Handler{
{
Name: "Execute post install hook",
Expand Down Expand Up @@ -467,6 +476,14 @@ func (t *TKE) runWithUI() error {
if t.isFromRestore {
go t.do()
}
if t.Config.Upgrade {
err := t.prepareForUpgrade(context.Background())
if err != nil {
return err
}
t.do()
return nil
}

log.Infof("Starting %s at http:https://%s", t.Config.ServerName, t.Config.ListenAddr)
return http.ListenAndServe(t.Config.ListenAddr, nil)
Expand Down Expand Up @@ -953,15 +970,22 @@ func (t *TKE) do() {
start := time.Now()
ctx := t.log.WithContext(context.Background())

containerregistry.Init(t.Para.Config.Registry.Domain(), t.Para.Config.Registry.Namespace())
t.initSteps()
var taskType string
if t.Config.Upgrade {
taskType = "upgrade"
t.upgradeSteps()
} else {
taskType = "install"
containerregistry.Init(t.Para.Config.Registry.Domain(), t.Para.Config.Registry.Namespace())
t.initSteps()
}

if t.Step == 0 {
t.log.Info("===>starting install task")
t.log.Infof("===>starting %s task", taskType)
t.progress.Status = types.StatusDoing
}

if t.runAfterClusterReady() {
if !t.Config.Upgrade && t.runAfterClusterReady() {
t.initDataForDeployTKE()
}

Expand Down Expand Up @@ -1020,7 +1044,7 @@ func (t *TKE) do() {
}
t.progress.Servers = append(t.progress.Servers, t.servers...)

t.log.Infof("===>install task [Sucesss] [%fs]", time.Since(start).Seconds())
t.log.Infof("===>%s task [Sucesss] [%fs]", taskType, time.Since(start).Seconds())
}

func (t *TKE) runAfterClusterReady() bool {
Expand Down Expand Up @@ -2425,14 +2449,15 @@ func (t *TKE) writeKubeconfig(ctx context.Context) error {
return ioutil.WriteFile("/root/.kube/config", data, 0644)
}

func (t *TKE) patchK8sValidVersions(ctx context.Context) error {
func (t *TKE) patchPlatformVersion(ctx context.Context) error {
versionsByte, err := json.Marshal(spec.K8sValidVersions)
if err != nil {
return err
}
patchData := map[string]interface{}{
"data": map[string]interface{}{
"k8sValidVersions": string(versionsByte),
"tkeVersion": spec.TKEVersion,
},
}
patchByte, err := json.Marshal(patchData)
Expand All @@ -2442,3 +2467,22 @@ func (t *TKE) patchK8sValidVersions(ctx context.Context) error {
_, err = t.globalClient.CoreV1().ConfigMaps("kube-public").Patch(ctx, "cluster-info", k8stypes.MergePatchType, patchByte, metav1.PatchOptions{})
return err
}

func (t *TKE) saveThirdPartyRegistryInfo(ctx context.Context) error {
if t.Para.Config.Registry.ThirdPartyRegistry == nil {
return errors.New("No third party registry info")
}
thirdPartyRegistryByte, err := json.Marshal(*t.Para.Config.Registry.ThirdPartyRegistry)
if err != nil {
return err
}
thirdPartyRegistryCm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: thirdPartyRegistryCmName,
Namespace: t.namespace,
},
Data: map[string]string{},
}
thirdPartyRegistryCm.Data[thirdPartyRegistryCmKey] = string(thirdPartyRegistryByte)
return apiclient.CreateOrUpdateConfigMap(ctx, t.globalClient, thirdPartyRegistryCm)
}
20 changes: 20 additions & 0 deletions cmd/tke-installer/app/installer/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type OIDCAuth struct {
type Registry struct {
TKERegistry *TKERegistry `json:"tke,omitempty"`
ThirdPartyRegistry *ThirdPartyRegistry `json:"thirdParty,omitempty"`
UserInputRegistry UserInputRegistry `json:"userInputRegistry,omitempty"`
}

type Audit struct {
Expand All @@ -87,27 +88,39 @@ type ElasticSearch struct {
}

func (r *Registry) Domain() string {
if r.UserInputRegistry.Domain != "" {
return r.UserInputRegistry.Domain
}
if r.ThirdPartyRegistry != nil { // first use third party when both set
return r.ThirdPartyRegistry.Domain
}
return r.TKERegistry.Domain
}

func (r *Registry) Namespace() string {
if r.UserInputRegistry.Namespace != "" {
return r.UserInputRegistry.Namespace
}
if r.ThirdPartyRegistry != nil {
return r.ThirdPartyRegistry.Namespace
}
return r.TKERegistry.Namespace
}

func (r *Registry) Username() string {
if r.UserInputRegistry.Username != "" {
return r.UserInputRegistry.Username
}
if r.ThirdPartyRegistry != nil {
return r.ThirdPartyRegistry.Username
}
return r.TKERegistry.Username
}

func (r *Registry) Password() []byte {
if len(r.UserInputRegistry.Password) != 0 {
return r.UserInputRegistry.Password
}
if r.ThirdPartyRegistry != nil {
return r.ThirdPartyRegistry.Password
}
Expand Down Expand Up @@ -138,6 +151,13 @@ type ThirdPartyRegistry struct {
Password []byte `json:"password"`
}

type UserInputRegistry struct {
Domain string `json:"domain"`
Namespace string `json:"namespace"`
Username string `json:"username"`
Password []byte `json:"password"`
}

type Business struct {
}

Expand Down
Loading