Skip to content

Commit

Permalink
feat: commit messaging and catalog user field (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
CristhianF7 authored Feb 15, 2024
1 parent 73a77df commit bf1ef84
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
16 changes: 12 additions & 4 deletions internal/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func CreateService(cl *pkgtypes.Cluster, serviceName string, appDef *pkgtypes.Gi
}

// Commit to gitops repository
err = gitClient.Commit(gitopsRepo, fmt.Sprintf("committing files for service %s", serviceName))
err = gitClient.Commit(gitopsRepo, fmt.Sprintf("adding %s to the cluster %s on behalf of %s", serviceName, clusterName, req.User))
if err != nil {
return fmt.Errorf("cluster %s - error committing service file: %s", clusterName, err)
}
Expand Down Expand Up @@ -218,6 +218,7 @@ func CreateService(cl *pkgtypes.Cluster, serviceName string, appDef *pkgtypes.Gi
Image: appDef.ImageURL,
Links: []string{},
Status: "",
CreatedBy: req.User,
})
if err != nil {
return err
Expand Down Expand Up @@ -360,10 +361,11 @@ func DeleteService(cl *pkgtypes.Cluster, serviceName string, def pkgtypes.Gitops
}

// Commit to gitops repository
err = gitClient.Commit(gitopsRepo, fmt.Sprintf("deleting files for service %s", serviceName))
err = gitClient.Commit(gitopsRepo, fmt.Sprintf("removing %s from the cluster %s on behalf of %s", serviceName, clusterName, def.User))
if err != nil {
return fmt.Errorf("cluster %s - error deleting service file: %s", clusterName, err)
}

err = gitopsRepo.Push(&git.PushOptions{
RemoteName: "origin",
Auth: &githttps.BasicAuth{
Expand Down Expand Up @@ -406,7 +408,8 @@ func AddDefaultServices(cl *pkgtypes.Cluster) error {
Image: fmt.Sprintf("https://assets.kubefirst.com/console/%s.svg", cl.GitProvider),
Links: []string{fmt.Sprintf("https://%s/%s/gitops", cl.GitHost, cl.GitAuth.Owner),
fmt.Sprintf("https://%s/%s/metaphor", cl.GitHost, cl.GitAuth.Owner)},
Status: "",
Status: "",
CreatedBy: "kbot",
},
{
Name: "Vault",
Expand All @@ -415,6 +418,7 @@ func AddDefaultServices(cl *pkgtypes.Cluster) error {
Image: "https://assets.kubefirst.com/console/vault.svg",
Links: []string{fmt.Sprintf("https://vault.%s", fullDomainName)},
Status: "",
CreatedBy: "kbot",
},
{
Name: "Argo CD",
Expand All @@ -423,6 +427,7 @@ func AddDefaultServices(cl *pkgtypes.Cluster) error {
Image: "https://assets.kubefirst.com/console/argocd.svg",
Links: []string{fmt.Sprintf("https://argocd.%s", fullDomainName)},
Status: "",
CreatedBy: "kbot",
},
{
Name: "Argo Workflows",
Expand All @@ -431,6 +436,7 @@ func AddDefaultServices(cl *pkgtypes.Cluster) error {
Image: "https://assets.kubefirst.com/console/argocd.svg",
Links: []string{fmt.Sprintf("https://argo.%s/workflows", fullDomainName)},
Status: "",
CreatedBy: "kbot",
},
{
Name: "Atlantis",
Expand All @@ -439,6 +445,7 @@ func AddDefaultServices(cl *pkgtypes.Cluster) error {
Image: "https://assets.kubefirst.com/console/atlantis.svg",
Links: []string{fmt.Sprintf("https://atlantis.%s", fullDomainName)},
Status: "",
CreatedBy: "kbot",
},
}

Expand All @@ -451,7 +458,8 @@ func AddDefaultServices(cl *pkgtypes.Cluster) error {
Links: []string{fmt.Sprintf("https://metaphor-development.%s", fullDomainName),
fmt.Sprintf("https://metaphor-staging.%s", fullDomainName),
fmt.Sprintf("https://metaphor-production.%s", fullDomainName)},
Status: "",
Status: "",
CreatedBy: "kbot",
})
}

Expand Down
1 change: 1 addition & 0 deletions internal/types/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Service struct {
Image string `bson:"image" json:"image"`
Links []string `bson:"links" json:"links"`
Status string `bson:"status" json:"status"`
CreatedBy string `bson:"created_by" json:"created_by"`
}

// ClusterServiceList tracks services per cluster
Expand Down
6 changes: 4 additions & 2 deletions pkg/types/gitopsCatalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ type GitopsCatalogAppKeys struct {
// GitopsCatalogAppCreateRequest describes a request to create a service for a cluster
// based on a gitops catalog app
type GitopsCatalogAppCreateRequest struct {
WorkloadClusterName string `bson:"workload_cluster_name" json:"workload_cluster_name"`
IsTemplate bool `bson:"is_template" json:"is_template"`
User string `bson:"user" json:"user"`
SecretKeys []GitopsCatalogAppKeys `bson:"secret_keys,omitempty" json:"secret_keys,omitempty"`
ConfigKeys []GitopsCatalogAppKeys `bson:"config_keys,omitempty" json:"config_keys,omitempty"`
WorkloadClusterName string `bson:"workload_cluster_name" json:"workload_cluster_name"`
}

type GitopsCatalogAppDeleteRequest struct {
WorkloadClusterName string `bson:"workload_cluster_name" json:"workload_cluster_name"`
User string `bson:"user" json:"user"`
IsTemplate bool `bson:"is_template" json:"is_template"`
WorkloadClusterName string `bson:"workload_cluster_name" json:"workload_cluster_name"`
}

0 comments on commit bf1ef84

Please sign in to comment.