From 073b3d602b5f89dfb779bc68a149493ee2911e52 Mon Sep 17 00:00:00 2001 From: Laszlo Fogas Date: Sat, 30 Nov 2024 17:44:20 +0100 Subject: [PATCH] New annotation (gimlet.io/app) to explicitelly associate k8s services with gimlet apps --- pkg/agent/kube.go | 2 + pkg/dashboard/api/types.go | 1 + web/src/components/env/env.jsx | 33 +++++++------ .../serviceDetail/serviceDetail.jsx | 46 +++++++++++-------- 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/pkg/agent/kube.go b/pkg/agent/kube.go index 11781a5bc..b2cce3f22 100644 --- a/pkg/agent/kube.go +++ b/pkg/agent/kube.go @@ -35,6 +35,7 @@ import ( ) const AnnotationGitRepository = "gimlet.io/git-repository" +const AnnotationApp = "gimlet.io/app" const AnnotationGitSha = "gimlet.io/git-sha" const AnnotationGitBranch = "gimlet.io/git-branch" const AnnotationDocsLink = "v1alpha1.opensca.dev/documentation" @@ -125,6 +126,7 @@ func (e *KubeEnv) Services(repo string) ([]*api.Stack, error) { stacks = append(stacks, &api.Stack{ Repo: service.ObjectMeta.GetAnnotations()[AnnotationGitRepository], + App: service.ObjectMeta.GetAnnotations()[AnnotationApp], Osca: getOpenServiceCatalogAnnotations(service), Service: &api.Service{Name: service.Name, Namespace: service.Namespace}, Deployment: deployment, diff --git a/pkg/dashboard/api/types.go b/pkg/dashboard/api/types.go index 0209bc8ea..d3bba94de 100644 --- a/pkg/dashboard/api/types.go +++ b/pkg/dashboard/api/types.go @@ -188,6 +188,7 @@ type AgentState struct { type Stack struct { Repo string `json:"repo"` Env string `json:"env"` + App string `json:"app"` Osca *Osca `json:"osca"` Service *Service `json:"service"` Deployment *Deployment `json:"deployment,omitempty"` diff --git a/web/src/components/env/env.jsx b/web/src/components/env/env.jsx index 27a402c28..eac1c750a 100644 --- a/web/src/components/env/env.jsx +++ b/web/src/components/env/env.jsx @@ -74,32 +74,31 @@ function renderServices( let configsWeDeployed = []; // render services that are deployed on k8s services = filteredStacks.map((stack) => { - configsWeDeployed.push(stack.service.name); - const configExists = configsWeHave.includes(stack.service.name) - let config = undefined; - if (configExists) { + let config = envConfigs.find((config) => config.app === stack.app); + if (!config) { config = envConfigs.find((config) => config.app === stack.service.name) } + configsWeDeployed.push(config.app); let deployment = ""; if (stack.deployment) { deployment = stack.deployment.namespace + "/" + stack.deployment.name } + const appOrServiceName = config ? config.app : stack.service.name return ( -
+
!configsWeDeployed.includes(config) && config.includes(appFilter)); - services.push( - ...configsWeHaventDeployed.sort().map(config => { + ...configsWeHaventDeployed.sort().map(configName => { + const config = envConfigs.find((config) => config.app === configName) return ( -
+
{ if (deploymentFromParams === stack.service.name) { window.scrollTo({ behavior: 'smooth', top: ref.current.offsetTop }) @@ -36,23 +38,25 @@ function ServiceDetail(props) { }, [deploymentFromParams, stack.service.name]); useEffect(() => { - gimletClient.getRolloutHistoryPerApp(owner, repoName, environment.name, stack.service.name) - .then(data => { - store.dispatch({ - type: ACTION_TYPE_ROLLOUT_HISTORY, payload: { - owner: owner, - repo: repoName, - env: environment.name, - app: stack.service.name, - releases: data, - } - }); - }, () => {/* Generic error handler deals with it */ }); - - gimletClient.getConfigChangePullRequestsPerConfig(owner, repoName, environment.name, stack.service.name) - .then(data => { - setPullRequests(data) - }) + if (config) { + gimletClient.getRolloutHistoryPerApp(owner, repoName, environment.name, config.app) + .then(data => { + store.dispatch({ + type: ACTION_TYPE_ROLLOUT_HISTORY, payload: { + owner: owner, + repo: repoName, + env: environment.name, + app: config.app, + releases: data, + } + }); + }, () => {/* Generic error handler deals with it */ }); + + gimletClient.getConfigChangePullRequestsPerConfig(owner, repoName, environment.name, config.app) + .then(data => { + setPullRequests(data) + }) + } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -194,7 +198,7 @@ function ServiceDetail(props) { onClick={() => { if (configExists) { posthog?.capture('Env config edit pushed') - navigateToConfigEdit(environment.name, stack.service.name) + navigateToConfigEdit(environment.name, config.app) } }} > @@ -345,12 +349,13 @@ function ServiceDetail(props) {
} + {config &&

Deploy History

+ }