Skip to content

Commit

Permalink
Refactor: refactor cd interface (#127)
Browse files Browse the repository at this point in the history
* refactor: cd simplify

Signed-off-by: closetool <[email protected]>

* chore: add paths to build image action

Signed-off-by: closetool <[email protected]>

* fix: autoPromote was covered after pausing

Signed-off-by: closetool <[email protected]>

* fix: some cemment

Signed-off-by: closetool <[email protected]>

* feat: support cancel release

Signed-off-by: closetool <[email protected]>

* fix: add description for action

Signed-off-by: closetool <[email protected]>

* fix: err returned from rollout actions

Signed-off-by: closetool <[email protected]>

---------

Signed-off-by: closetool <[email protected]>
  • Loading branch information
kilosonc authored Apr 20, 2023
1 parent f07df8f commit d6b5c09
Show file tree
Hide file tree
Showing 46 changed files with 1,106 additions and 1,140 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
push:
branches:
- main
paths:
- "**.go"
- "!**_test.go"
- "build/**"
tags:
- v*

Expand Down
3 changes: 2 additions & 1 deletion core/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import (
"github.com/horizoncd/horizon/core/middleware/auth"
"github.com/horizoncd/horizon/core/middleware/requestid"
gitlablib "github.com/horizoncd/horizon/lib/gitlab"
"github.com/horizoncd/horizon/pkg/cd"
"github.com/horizoncd/horizon/pkg/environment/service"
"github.com/horizoncd/horizon/pkg/grafana"
"github.com/horizoncd/horizon/pkg/jobs"
Expand Down Expand Up @@ -124,7 +125,6 @@ import (
"github.com/horizoncd/horizon/pkg/application/gitrepo"
applicationservice "github.com/horizoncd/horizon/pkg/application/service"
userauth "github.com/horizoncd/horizon/pkg/authentication/user"
"github.com/horizoncd/horizon/pkg/cluster/cd"
"github.com/horizoncd/horizon/pkg/cluster/code"
clustergitrepo "github.com/horizoncd/horizon/pkg/cluster/gitrepo"
clusterservice "github.com/horizoncd/horizon/pkg/cluster/service"
Expand Down Expand Up @@ -438,6 +438,7 @@ func Init(ctx context.Context, flags *Flags, coreConfig *config.Config) {
ApplicationGitRepo: applicationGitRepo,
TemplateSchemaGetter: templateSchemaGetter,
Cd: cd.NewCD(clusterGitRepo, coreConfig.ArgoCDMapper, flags.GitOpsRepoDefaultBranch),
K8sUtil: cd.NewK8sUtil(),
OutputGetter: outputGetter,
TektonFty: tektonFty,
ClusterGitRepo: clusterGitRepo,
Expand Down
5 changes: 5 additions & 0 deletions core/common/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const (
ClusterQueryIsFavorite = "isFavorite"
// ClusterQueryWithFavorite is used to query cluster with favorite field inside.
ClusterQueryWithFavorite = "withFavorite"
ClusterQueryAction = "action"

ClusterQueryByGVK = "gvk"

ClusterQueryResourceName = "resourceName"
)

const (
Expand Down
13 changes: 7 additions & 6 deletions core/controller/cluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
appgitrepo "github.com/horizoncd/horizon/pkg/application/gitrepo"
appmanager "github.com/horizoncd/horizon/pkg/application/manager"
applicationservice "github.com/horizoncd/horizon/pkg/application/service"
"github.com/horizoncd/horizon/pkg/cluster/cd"
"github.com/horizoncd/horizon/pkg/cd"
"github.com/horizoncd/horizon/pkg/cluster/code"
"github.com/horizoncd/horizon/pkg/cluster/gitrepo"
clustermanager "github.com/horizoncd/horizon/pkg/cluster/manager"
Expand Down Expand Up @@ -39,6 +39,7 @@ import (
tokenservice "github.com/horizoncd/horizon/pkg/token/service"
usermanager "github.com/horizoncd/horizon/pkg/user/manager"
usersvc "github.com/horizoncd/horizon/pkg/user/service"
"k8s.io/apimachinery/pkg/runtime/schema"
)

type Controller interface {
Expand Down Expand Up @@ -68,10 +69,8 @@ type Controller interface {
InternalDeploy(ctx context.Context, clusterID uint,
r *InternalDeployRequest) (_ *InternalDeployResponse, err error)

Promote(ctx context.Context, clusterID uint) error
Pause(ctx context.Context, clusterID uint) error
Resume(ctx context.Context, clusterID uint) error
Next(ctx context.Context, clusterID uint) error
ExecuteAction(ctx context.Context, clusterID uint, action string,
gvk schema.GroupVersionResource) error

// Deprecated: GetClusterStatus
GetClusterStatus(ctx context.Context, clusterID uint) (_ *GetClusterStatusResponse, err error)
Expand All @@ -82,7 +81,7 @@ type Controller interface {
Exec(ctx context.Context, clusterID uint, r *ExecRequest) (_ ExecResponse, err error)

GetDiff(ctx context.Context, clusterID uint, refType, ref string) (*GetDiffResponse, error)
GetContainerLog(ctx context.Context, clusterID uint, podName, containerName string, tailLines int) (
GetContainerLog(ctx context.Context, clusterID uint, podName, containerName string, tailLines int64) (
<-chan string, error)

DeleteClusterPods(ctx context.Context, clusterID uint, podName []string) (BatchResponse, error)
Expand Down Expand Up @@ -116,6 +115,7 @@ type controller struct {
applicationGitRepo appgitrepo.ApplicationGitRepo
commitGetter code.GitGetter
cd cd.CD
k8sutil cd.K8sUtil
applicationMgr appmanager.Manager
autoFreeSvc *service.AutoFreeSVC
applicationSvc applicationservice.Service
Expand Down Expand Up @@ -155,6 +155,7 @@ func NewController(config *config.Config, param *param.Param) Controller {
applicationGitRepo: param.ApplicationGitRepo,
commitGetter: param.GitGetter,
cd: param.Cd,
k8sutil: param.K8sUtil,
applicationMgr: param.ApplicationManager,
applicationSvc: param.ApplicationSvc,
templateReleaseMgr: param.TemplateReleaseManager,
Expand Down
2 changes: 1 addition & 1 deletion core/controller/cluster/controller_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/horizoncd/horizon/core/middleware/requestid"
"github.com/horizoncd/horizon/lib/q"
"github.com/horizoncd/horizon/pkg/application/models"
"github.com/horizoncd/horizon/pkg/cluster/cd"
"github.com/horizoncd/horizon/pkg/cd"
codemodels "github.com/horizoncd/horizon/pkg/cluster/code"
"github.com/horizoncd/horizon/pkg/cluster/gitrepo"
cmodels "github.com/horizoncd/horizon/pkg/cluster/models"
Expand Down
2 changes: 1 addition & 1 deletion core/controller/cluster/controller_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/horizoncd/horizon/core/common"
"github.com/horizoncd/horizon/lib/q"
mockcd "github.com/horizoncd/horizon/mock/pkg/cluster/cd"
mockcd "github.com/horizoncd/horizon/mock/pkg/cd"
appmodels "github.com/horizoncd/horizon/pkg/application/models"
applicationservice "github.com/horizoncd/horizon/pkg/application/service"
userauth "github.com/horizoncd/horizon/pkg/authentication/user"
Expand Down
4 changes: 2 additions & 2 deletions core/controller/cluster/controller_basic_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
herrors "github.com/horizoncd/horizon/core/errors"
appgitrepo "github.com/horizoncd/horizon/pkg/application/gitrepo"
appmodels "github.com/horizoncd/horizon/pkg/application/models"
"github.com/horizoncd/horizon/pkg/cluster/cd"
"github.com/horizoncd/horizon/pkg/cd"
"github.com/horizoncd/horizon/pkg/cluster/gitrepo"
collectionmodels "github.com/horizoncd/horizon/pkg/collection/models"
eventmodels "github.com/horizoncd/horizon/pkg/event/models"
Expand Down Expand Up @@ -63,7 +63,7 @@ func (c *controller) GetClusterStatusV2(ctx context.Context, clusterID uint) (*S
// If cluster not found on argo, check the cluster is freed or has not been published yet,
// or the cluster will be "notFound". If response's status field has not been set,
// set it with status from argocd.
cdStatus, err := c.cd.GetClusterStateV2(ctx, params)
cdStatus, err := c.cd.GetClusterState(ctx, params)
if err != nil {
if _, ok := perror.Cause(err).(*herrors.HorizonErrNotFound); !ok {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion core/controller/cluster/controller_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/horizoncd/horizon/core/common"
herrors "github.com/horizoncd/horizon/core/errors"
"github.com/horizoncd/horizon/pkg/cluster/cd"
"github.com/horizoncd/horizon/pkg/cd"
codemodels "github.com/horizoncd/horizon/pkg/cluster/code"
"github.com/horizoncd/horizon/pkg/cluster/gitrepo"
perror "github.com/horizoncd/horizon/pkg/errors"
Expand Down
2 changes: 1 addition & 1 deletion core/controller/cluster/controller_internal_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/horizoncd/horizon/core/common"
herrors "github.com/horizoncd/horizon/core/errors"
userauth "github.com/horizoncd/horizon/pkg/authentication/user"
"github.com/horizoncd/horizon/pkg/cluster/cd"
"github.com/horizoncd/horizon/pkg/cd"
"github.com/horizoncd/horizon/pkg/cluster/gitrepo"
perror "github.com/horizoncd/horizon/pkg/errors"
eventmodels "github.com/horizoncd/horizon/pkg/event/models"
Expand Down
Loading

0 comments on commit d6b5c09

Please sign in to comment.