Skip to content

Commit

Permalink
feat(installer): complete registry and application component
Browse files Browse the repository at this point in the history
  • Loading branch information
jianzhuang authored and tke-robot committed Sep 3, 2020
1 parent 2e00cf7 commit e0f2578
Show file tree
Hide file tree
Showing 14 changed files with 965 additions and 72 deletions.
1 change: 1 addition & 0 deletions cmd/tke-installer/app/installer/certs/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var (
"tke-registry-api",
"tke-logagent-api",
"tke-audit-api",
"tke-application-api",
}
)

Expand Down
66 changes: 36 additions & 30 deletions cmd/tke-installer/app/installer/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,24 @@ type Components struct {

ProviderRes containerregistry.Image

TKEGateway containerregistry.Image
TKEAuthAPI containerregistry.Image
TKEAuthController containerregistry.Image
TKEBusinessAPI containerregistry.Image
TKEBusinessController containerregistry.Image
TKEMonitorAPI containerregistry.Image
TKEMonitorController containerregistry.Image
TKENotifyAPI containerregistry.Image
TKENotifyController containerregistry.Image
TKEPlatformAPI containerregistry.Image
TKEPlatformController containerregistry.Image
TKERegistryAPI containerregistry.Image
TKELogagentAPI containerregistry.Image
TKELogagentController containerregistry.Image
TKEAudit containerregistry.Image
TKEGateway containerregistry.Image
TKEAuthAPI containerregistry.Image
TKEAuthController containerregistry.Image
TKEBusinessAPI containerregistry.Image
TKEBusinessController containerregistry.Image
TKEMonitorAPI containerregistry.Image
TKEMonitorController containerregistry.Image
TKENotifyAPI containerregistry.Image
TKENotifyController containerregistry.Image
TKEPlatformAPI containerregistry.Image
TKEPlatformController containerregistry.Image
TKERegistryAPI containerregistry.Image
TKERegistryController containerregistry.Image
TKELogagentAPI containerregistry.Image
TKELogagentController containerregistry.Image
TKEAudit containerregistry.Image
TKEApplicationAPI containerregistry.Image
TKEApplicationController containerregistry.Image
}

func (c Components) Get(name string) *containerregistry.Image {
Expand All @@ -71,21 +74,24 @@ var components = Components{

ProviderRes: containerregistry.Image{Name: "provider-res", Tag: "v1.18.3-1"},

TKEAuthAPI: containerregistry.Image{Name: "tke-auth-api", Tag: Version},
TKEAuthController: containerregistry.Image{Name: "tke-auth-controller", Tag: Version},
TKEBusinessAPI: containerregistry.Image{Name: "tke-business-api", Tag: Version},
TKEBusinessController: containerregistry.Image{Name: "tke-business-controller", Tag: Version},
TKEGateway: containerregistry.Image{Name: "tke-gateway", Tag: Version},
TKEMonitorAPI: containerregistry.Image{Name: "tke-monitor-api", Tag: Version},
TKEMonitorController: containerregistry.Image{Name: "tke-monitor-controller", Tag: Version},
TKENotifyAPI: containerregistry.Image{Name: "tke-notify-api", Tag: Version},
TKENotifyController: containerregistry.Image{Name: "tke-notify-controller", Tag: Version},
TKEPlatformAPI: containerregistry.Image{Name: "tke-platform-api", Tag: Version},
TKEPlatformController: containerregistry.Image{Name: "tke-platform-controller", Tag: Version},
TKERegistryAPI: containerregistry.Image{Name: "tke-registry-api", Tag: Version},
TKELogagentAPI: containerregistry.Image{Name: "tke-logagent-api", Tag: Version},
TKELogagentController: containerregistry.Image{Name: "tke-logagent-controller", Tag: Version},
TKEAudit: containerregistry.Image{Name: "tke-audit-api", Tag: Version},
TKEAuthAPI: containerregistry.Image{Name: "tke-auth-api", Tag: Version},
TKEAuthController: containerregistry.Image{Name: "tke-auth-controller", Tag: Version},
TKEBusinessAPI: containerregistry.Image{Name: "tke-business-api", Tag: Version},
TKEBusinessController: containerregistry.Image{Name: "tke-business-controller", Tag: Version},
TKEGateway: containerregistry.Image{Name: "tke-gateway", Tag: Version},
TKEMonitorAPI: containerregistry.Image{Name: "tke-monitor-api", Tag: Version},
TKEMonitorController: containerregistry.Image{Name: "tke-monitor-controller", Tag: Version},
TKENotifyAPI: containerregistry.Image{Name: "tke-notify-api", Tag: Version},
TKENotifyController: containerregistry.Image{Name: "tke-notify-controller", Tag: Version},
TKEPlatformAPI: containerregistry.Image{Name: "tke-platform-api", Tag: Version},
TKEPlatformController: containerregistry.Image{Name: "tke-platform-controller", Tag: Version},
TKERegistryAPI: containerregistry.Image{Name: "tke-registry-api", Tag: Version},
TKERegistryController: containerregistry.Image{Name: "tke-registry-controller", Tag: Version},
TKELogagentAPI: containerregistry.Image{Name: "tke-logagent-api", Tag: Version},
TKELogagentController: containerregistry.Image{Name: "tke-logagent-controller", Tag: Version},
TKEAudit: containerregistry.Image{Name: "tke-audit-api", Tag: Version},
TKEApplicationAPI: containerregistry.Image{Name: "tke-application-api", Tag: Version},
TKEApplicationController: containerregistry.Image{Name: "tke-application-controller", Tag: Version},
}

func List() []string {
Expand Down
136 changes: 120 additions & 16 deletions cmd/tke-installer/app/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ func (t *TKE) initSteps() {
Name: "Install tke-registry-api",
Func: t.installTKERegistryAPI,
},
{
Name: "Install tke-registry-controller",
Func: t.installTKERegistryController,
},
}...)
}

Expand Down Expand Up @@ -334,6 +338,19 @@ func (t *TKE) initSteps() {
}...)
}

if t.Para.Config.Application != nil {
t.steps = append(t.steps, []types.Handler{
{
Name: "Install tke-application-api",
Func: t.installTKEApplicationAPI,
},
{
Name: "Install tke-application-controller",
Func: t.installTKEApplicationController,
},
}...)
}

// others

// Add more tke component before THIS!!!
Expand Down Expand Up @@ -597,7 +614,18 @@ func (t *TKE) setConfigDefault(config *types.Config) {
}

config.Logagent = new(types.Logagent)

//TODO: remove default installation
config.Application = new(types.Application)
if config.Application != nil {
if config.Application.RegistryDomain == "" {
config.Application.RegistryDomain = "registry.tke.com"
}
config.Application.RegistryUsername = config.Basic.Username
config.Application.RegistryPassword = config.Basic.Password
}
}

func (t *TKE) setClusterDefault(cluster *platformv1.Cluster, config *types.Config) {
if cluster.APIVersion == "" {
cluster.APIVersion = platformv1.SchemeGroupVersion.String()
Expand Down Expand Up @@ -1435,15 +1463,16 @@ func (t *TKE) stopLocalRegistry(ctx context.Context) error {

func (t *TKE) installTKEGateway(ctx context.Context) error {
option := map[string]interface{}{
"Image": images.Get().TKEGateway.FullName(),
"OIDCClientSecret": t.readOrGenerateString(constants.OIDCClientSecretFile),
"SelfSigned": t.Para.Config.Gateway.Cert.SelfSignedCert != nil,
"EnableRegistry": t.Para.Config.Registry.TKERegistry != nil,
"EnableAuth": t.Para.Config.Auth.TKEAuth != nil,
"EnableMonitor": t.Para.Config.Monitor != nil,
"EnableBusiness": t.businessEnabled(),
"EnableLogagent": t.Para.Config.Logagent != nil,
"EnableAudit": t.auditEnabled(),
"Image": images.Get().TKEGateway.FullName(),
"OIDCClientSecret": t.readOrGenerateString(constants.OIDCClientSecretFile),
"SelfSigned": t.Para.Config.Gateway.Cert.SelfSignedCert != nil,
"EnableRegistry": t.Para.Config.Registry.TKERegistry != nil,
"EnableAuth": t.Para.Config.Auth.TKEAuth != nil,
"EnableMonitor": t.Para.Config.Monitor != nil,
"EnableBusiness": t.Para.Config.Business != nil,
"EnableLogagent": t.Para.Config.Logagent != nil,
"EnableAudit": t.auditEnabled(),
"EnableApplication": t.Para.Config.Application != nil,
}
if t.Para.Config.Registry.TKERegistry != nil {
option["RegistryDomainSuffix"] = t.Para.Config.Registry.TKERegistry.Domain
Expand Down Expand Up @@ -1918,13 +1947,13 @@ func (t *TKE) installTKENotifyController(ctx context.Context) error {

func (t *TKE) installTKERegistryAPI(ctx context.Context) error {
options := map[string]interface{}{
"Image": images.Get().TKERegistryAPI.FullName(),
"NodeName": t.servers[0],
"AdminUsername": t.Para.Config.Registry.TKERegistry.Username,
"AdminPassword": string(t.Para.Config.Registry.TKERegistry.Password),
"EnableAuth": t.Para.Config.Auth.TKEAuth != nil,
"DomainSuffix": t.Para.Config.Registry.TKERegistry.Domain,
"EnableAudit": t.auditEnabled(),
"Image": images.Get().TKERegistryAPI.FullName(),
"NodeName": t.servers[0],
"AdminUsername": t.Para.Config.Registry.TKERegistry.Username,
"AdminPassword": string(t.Para.Config.Registry.TKERegistry.Password),
"EnableAuth": t.Para.Config.Auth.TKEAuth != nil,
"EnableBusiness": t.Para.Config.Business != nil,
"DomainSuffix": t.Para.Config.Registry.TKERegistry.Domain,
}
if t.Para.Config.Auth.OIDCAuth != nil {
options["OIDCClientID"] = t.Para.Config.Auth.OIDCAuth.ClientID
Expand All @@ -1945,6 +1974,78 @@ func (t *TKE) installTKERegistryAPI(ctx context.Context) error {
})
}

func (t *TKE) installTKERegistryController(ctx context.Context) error {
err := apiclient.CreateResourceWithDir(ctx, t.globalClient, "manifests/tke-registry-controller/*.yaml",
map[string]interface{}{
"Replicas": t.Config.Replicas,
"Image": images.Get().TKERegistryController.FullName(),
"NodeName": t.servers[0],
"AdminUsername": t.Para.Config.Registry.TKERegistry.Username,
"AdminPassword": string(t.Para.Config.Registry.TKERegistry.Password),
"EnableAuth": t.Para.Config.Auth.TKEAuth != nil,
"EnableBusiness": t.Para.Config.Business != nil,
"DomainSuffix": t.Para.Config.Registry.TKERegistry.Domain,
})
if err != nil {
return err
}

return wait.PollImmediate(5*time.Second, 10*time.Minute, func() (bool, error) {
ok, err := apiclient.CheckDeployment(ctx, t.globalClient, t.namespace, "tke-registry-controller")
if err != nil {
return false, nil
}
return ok, nil
})
}

func (t *TKE) installTKEApplicationAPI(ctx context.Context) error {
options := map[string]interface{}{
"Image": images.Get().TKEApplicationAPI.FullName(),
"EnableAuth": t.Para.Config.Auth.TKEAuth != nil,
"EnableRegistry": t.Para.Config.Registry.TKERegistry != nil,
}
if t.Para.Config.Auth.OIDCAuth != nil {
options["OIDCClientID"] = t.Para.Config.Auth.OIDCAuth.ClientID
options["OIDCIssuerURL"] = t.Para.Config.Auth.OIDCAuth.IssuerURL
options["UseOIDCCA"] = t.Para.Config.Auth.OIDCAuth.CACert != nil
}
err := apiclient.CreateResourceWithDir(ctx, t.globalClient, "manifests/tke-application-api/*.yaml", options)
if err != nil {
return err
}

return wait.PollImmediate(5*time.Second, 10*time.Minute, func() (bool, error) {
ok, err := apiclient.CheckDeployment(ctx, t.globalClient, t.namespace, "tke-application-api")
if err != nil {
return false, nil
}
return ok, nil
})
}

func (t *TKE) installTKEApplicationController(ctx context.Context) error {
err := apiclient.CreateResourceWithDir(ctx, t.globalClient, "manifests/tke-application-controller/*.yaml",
map[string]interface{}{
"Replicas": t.Config.Replicas,
"Image": images.Get().TKEApplicationController.FullName(),
"AdminUsername": t.Para.Config.Registry.TKERegistry.Username,
"AdminPassword": string(t.Para.Config.Registry.TKERegistry.Password),
"DomainSuffix": t.Para.Config.Registry.TKERegistry.Domain,
})
if err != nil {
return err
}

return wait.PollImmediate(5*time.Second, 10*time.Minute, func() (bool, error) {
ok, err := apiclient.CheckDeployment(ctx, t.globalClient, t.namespace, "tke-application-controller")
if err != nil {
return false, nil
}
return ok, nil
})
}

func (t *TKE) preparePushImagesToTKERegistry(ctx context.Context) error {
if !t.docker.Healthz() {
t.log.Info("Actively exit in order to reconnect to the docker service")
Expand Down Expand Up @@ -2011,6 +2112,9 @@ func (t *TKE) registerAPI(ctx context.Context) error {
if t.Para.Config.Registry.TKERegistry != nil {
svcs = append(svcs, "tke-registry-api")
}
if t.Para.Config.Application != nil {
svcs = append(svcs, "tke-application-api")
}
for _, one := range svcs {
name := strings.TrimSuffix(one[4:], "-api")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Tencent is pleased to support the open source community by making TKEStack
* available.
*
* Copyright (C) 2012-2020 Tencent. All Rights Reserved.
*
* 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
*
* https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package manifest

import (
"testing"

"github.com/stretchr/testify/assert"
"tkestack.io/tke/pkg/kubectl"
"tkestack.io/tke/pkg/util/template"
)

func TestManifest(t *testing.T) {
data, err := template.ParseFile("tke-application-api.yaml",
map[string]interface{}{
"Replicas": 1,
"Image": "Image",
"EnableAuth": true,
"EnableAudit": true,
"EnableRegistry": true,
})
if !assert.Nil(t, err) {
t.FailNow()
}

data, err = kubectl.Validate(data)
if !assert.Nil(t, err) {
t.Fatal(string(data))
}
}
Loading

0 comments on commit e0f2578

Please sign in to comment.