Skip to content

Commit

Permalink
chore: improve install bash (#134)
Browse files Browse the repository at this point in the history
* chore: improve install bash

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

* fix: do not dependent github strongly

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

* fix: add visibility for gitops repo

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

* fix: install script gitops defaultBranch

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

* fix: add test for template controller

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

* fix: app gitops repo

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

* fix: using horizoncd hello-world as example

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

* refactor: rename Cd to CD

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

---------

Signed-off-by: closetool <[email protected]>
  • Loading branch information
kilosonc authored Apr 26, 2023
1 parent 518de1c commit 5bfbe36
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 241 deletions.
50 changes: 25 additions & 25 deletions core/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,14 @@ import (

// Flags defines agent CLI flags.
type Flags struct {
ConfigFile string
RoleConfigFile string
ScopeRoleFile string
BuildJSONSchemaFile string
BuildUISchemaFile string
Dev bool
Environment string
LogLevel string
GitOpsRepoDefaultBranch string
ConfigFile string
RoleConfigFile string
ScopeRoleFile string
BuildJSONSchemaFile string
BuildUISchemaFile string
Dev bool
Environment string
LogLevel string
}

type RegisterRouter interface {
Expand Down Expand Up @@ -215,10 +214,6 @@ func ParseFlags() *Flags {
flag.StringVar(
&flags.LogLevel, "loglevel", "info", "the loglevel(panic/fatal/error/warn/info/debug/trace))")

flag.StringVar(
&flags.GitOpsRepoDefaultBranch, "gitOpsRepoDefaultBranch", "master",
"configure gitops git engine default branch")

flag.Parse()
return &flags
}
Expand Down Expand Up @@ -326,14 +321,18 @@ func Init(ctx context.Context, flags *Flags, coreConfig *config.Config) {
rootGroup, err := gitlabGitops.GetGroup(ctx, rootGroupPath)
if err != nil {
log.Printf("failed to get gitops root group, error: %s, start to create it", err.Error())
rootGroup, err = gitlabGitops.CreateGroup(ctx, rootGroupPath, rootGroupPath, nil)
rootGroup, err = gitlabGitops.CreateGroup(ctx, rootGroupPath, rootGroupPath,
nil, coreConfig.GitopsRepoConfig.DefaultVisibility)
if err != nil {
panic(err)
}
}

applicationGitRepo, err := gitrepo.NewApplicationGitlabRepo(ctx, rootGroup, gitlabGitops,
flags.GitOpsRepoDefaultBranch)
applicationGitRepo, err := gitrepo.NewApplicationGitlabRepo(ctx, gitlabGitops, gitrepo.ApplicationGitRepoConfig{
RootGroup: rootGroup,
DefaultBranch: coreConfig.GitopsRepoConfig.DefaultBranch,
DefaultVisibility: coreConfig.GitopsRepoConfig.DefaultVisibility,
})

if err != nil {
panic(err)
Expand All @@ -345,7 +344,7 @@ func Init(ctx context.Context, flags *Flags, coreConfig *config.Config) {
}

clusterGitRepo, err := clustergitrepo.NewClusterGitlabRepo(ctx, rootGroup, templateRepo, gitlabGitops,
flags.GitOpsRepoDefaultBranch)
coreConfig.GitopsRepoConfig.DefaultBranch, coreConfig.GitopsRepoConfig.DefaultVisibility)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -451,14 +450,15 @@ func Init(ctx context.Context, flags *Flags, coreConfig *config.Config) {
ScopeService: scopeService,
ApplicationGitRepo: applicationGitRepo,
TemplateSchemaGetter: templateSchemaGetter,
Cd: cd.NewCD(clusterGitRepo, coreConfig.ArgoCDMapper, flags.GitOpsRepoDefaultBranch),
K8sUtil: cd.NewK8sUtil(),
OutputGetter: outputGetter,
TektonFty: tektonFty,
ClusterGitRepo: clusterGitRepo,
GitGetter: gitGetter,
GrafanaService: grafanaService,
BuildSchema: buildSchema,
CD: cd.NewCD(clusterGitRepo, coreConfig.ArgoCDMapper,
coreConfig.GitopsRepoConfig.DefaultVisibility),
K8sUtil: cd.NewK8sUtil(),
OutputGetter: outputGetter,
TektonFty: tektonFty,
ClusterGitRepo: clusterGitRepo,
GitGetter: gitGetter,
GrafanaService: grafanaService,
BuildSchema: buildSchema,
}

var (
Expand Down
2 changes: 1 addition & 1 deletion core/controller/cluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func NewController(config *config.Config, param *param.Param) Controller {
clusterGitRepo: param.ClusterGitRepo,
applicationGitRepo: param.ApplicationGitRepo,
commitGetter: param.GitGetter,
cd: param.Cd,
cd: param.CD,
k8sutil: param.K8sUtil,
applicationMgr: param.ApplicationManager,
applicationSvc: param.ApplicationSvc,
Expand Down
21 changes: 18 additions & 3 deletions core/controller/cluster/controller_build_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ func (c *controller) BuildDeploy(ctx context.Context, clusterID uint,

commit, err := c.commitGetter.GetCommit(ctx, cluster.GitURL, gitRefType, gitRef)
if err != nil {
return nil, err
commit = &git.Commit{
Message: "commit not found",
ID: gitRef,
}
}

regionEntity, err := c.regionMgr.GetRegionEntity(ctx, cluster.RegionName)
Expand Down Expand Up @@ -194,8 +197,12 @@ func assembleImageURL(regionEntity *regionmodels.RegionEntity,
normalizedBranch := strings.Join(pinyin.LazyPinyin(branch, args), "")
normalizedBranch = regexp.MustCompile(`[^a-zA-Z0-9_.-]`).ReplaceAllString(normalizedBranch, "_")

if len(commit) > 8 {
commit = commit[:8]
}

return path.Join(domain, regionEntity.Registry.Path, application,
fmt.Sprintf("%v:%v-%v-%v", cluster, normalizedBranch, commit[:8], timeStr))
fmt.Sprintf("%v:%v-%v-%v", cluster, normalizedBranch, commit, timeStr))
}

func (c *controller) GetDiff(ctx context.Context, clusterID uint, refType, ref string) (_ *GetDiffResponse, err error) {
Expand All @@ -219,7 +226,15 @@ func (c *controller) GetDiff(ctx context.Context, clusterID uint, refType, ref s
if ref != "" {
commit, err = c.commitGetter.GetCommit(ctx, cluster.GitURL, refType, ref)
if err != nil {
return nil, err
commit = &git.Commit{
ID: ref,
Message: fmt.Sprintf("failed to get commit message: %s", err),
}
}
} else {
commit = &git.Commit{
ID: "",
Message: "no commit",
}
}

Expand Down
Loading

0 comments on commit 5bfbe36

Please sign in to comment.