Skip to content

Commit

Permalink
add upgradejob controller
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksontong committed Apr 5, 2024
1 parent 87a4e03 commit 2545e22
Show file tree
Hide file tree
Showing 7 changed files with 786 additions and 28 deletions.
8 changes: 8 additions & 0 deletions cmd/tke-application-controller/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package app
import (
"fmt"
"net/http"
"os"
"time"

"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -74,6 +75,7 @@ type ControllerContext struct {
ResyncPeriod func() time.Duration
ControllerStartInterval time.Duration

Region string
Repo appconfig.RepoConfiguration
PlatformClient platformv1.PlatformV1Interface
}
Expand Down Expand Up @@ -114,6 +116,11 @@ func CreateControllerContext(cfg *config.Config, rootClientBuilder controller.Cl
return ControllerContext{}, err
}

region := os.Getenv("REGION")
if region == "" {
return ControllerContext{}, fmt.Errorf("Please set env REGION")
}

ctx := ControllerContext{
ClientBuilder: rootClientBuilder,
InformerFactory: sharedInformers,
Expand All @@ -125,6 +132,7 @@ func CreateControllerContext(cfg *config.Config, rootClientBuilder controller.Cl
ResyncPeriod: controller.ResyncPeriod(&cfg.Component),
ControllerStartInterval: cfg.Component.ControllerStartInterval,

Region: region,
Repo: cfg.RepoConfiguration,
PlatformClient: platformClient.PlatformV1(),
}
Expand Down
1 change: 1 addition & 0 deletions cmd/tke-application-controller/app/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func NewControllerInitializers() map[string]InitFunc {
controllers := map[string]InitFunc{}

controllers["app"] = startAppController
controllers["upgradejob"] = startUpgradeJobController
return controllers
}

Expand Down
46 changes: 46 additions & 0 deletions cmd/tke-application-controller/app/upgradejob.go
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-2019 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 app

import (
"net/http"
"time"

"k8s.io/apimachinery/pkg/runtime/schema"

applicationv1 "tkestack.io/tke/api/application/v1"
"tkestack.io/tke/pkg/application/controller/upgradejob"
)

func startUpgradeJobController(ctx ControllerContext) (http.Handler, bool, error) {
if !ctx.AvailableResources[schema.GroupVersionResource{Group: applicationv1.GroupName, Version: "v1", Resource: "apps"}] {
return nil, false, nil
}

ctrl := upgradejob.NewController(
ctx.ClientBuilder.ClientOrDie("app-upgradejob-controller"),
ctx.PlatformClient,
ctx.InformerFactory.Application().V1().UpgradeJobs(),
time.Second*10, //ctx.Config.AppControllerConfiguration.SyncPeriod,
ctx.Region,
)

go ctrl.Run(ctx.Config.AppControllerConfiguration.ConcurrentSyncs, ctx.Stop)
return nil, true, nil
}
25 changes: 14 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ require (
go.etcd.io/etcd/client/pkg/v3 v3.5.1
go.etcd.io/etcd/client/v3 v3.5.1
go.uber.org/zap v1.19.0
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd
golang.org/x/crypto v0.19.0
golang.org/x/net v0.21.0
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
google.golang.org/grpc v1.43.0
google.golang.org/grpc v1.62.1
gopkg.in/go-playground/validator.v9 v9.29.1
gopkg.in/ldap.v2 v2.5.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0
Expand Down Expand Up @@ -124,7 +124,10 @@ require (
yunion.io/x/pkg v0.0.0-20200603123312-ad58e621aec0
)

require golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3
require (
git.woa.com/kmetis/healthcheckpro v0.0.0-20240325053646-df0498237ffd
golang.org/x/mod v0.8.0
)

require (
cloud.google.com/go v0.99.0 // indirect
Expand Down Expand Up @@ -189,7 +192,7 @@ require (
github.com/go-kit/kit v0.10.0 // indirect
github.com/go-ldap/ldap/v3 v3.3.0 // indirect
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
Expand All @@ -201,7 +204,7 @@ require (
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.6 // indirect
Expand Down Expand Up @@ -292,14 +295,14 @@ require (
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/api v0.61.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand All @@ -308,7 +311,7 @@ require (
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
istio.io/gogo-genproto v0.0.0-20190930162913-45029607206a // indirect
k8s.io/helm v2.16.12+incompatible // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
oras.land/oras-go v1.1.0 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.30 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
Expand Down
Loading

0 comments on commit 2545e22

Please sign in to comment.