Skip to content
This repository was archived by the owner on Mar 9, 2025. It is now read-only.

Commit 491daa5

Browse files
authored
New annotation (gimlet.io/app) to explicitelly associate k8s services with gimlet apps (#884)
1 parent 2cc48f5 commit 491daa5

File tree

4 files changed

+45
-37
lines changed

4 files changed

+45
-37
lines changed

pkg/agent/kube.go

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
)
3636

3737
const AnnotationGitRepository = "gimlet.io/git-repository"
38+
const AnnotationApp = "gimlet.io/app"
3839
const AnnotationGitSha = "gimlet.io/git-sha"
3940
const AnnotationGitBranch = "gimlet.io/git-branch"
4041
const AnnotationDocsLink = "v1alpha1.opensca.dev/documentation"
@@ -125,6 +126,7 @@ func (e *KubeEnv) Services(repo string) ([]*api.Stack, error) {
125126

126127
stacks = append(stacks, &api.Stack{
127128
Repo: service.ObjectMeta.GetAnnotations()[AnnotationGitRepository],
129+
App: service.ObjectMeta.GetAnnotations()[AnnotationApp],
128130
Osca: getOpenServiceCatalogAnnotations(service),
129131
Service: &api.Service{Name: service.Name, Namespace: service.Namespace},
130132
Deployment: deployment,

pkg/dashboard/api/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ type AgentState struct {
188188
type Stack struct {
189189
Repo string `json:"repo"`
190190
Env string `json:"env"`
191+
App string `json:"app"`
191192
Osca *Osca `json:"osca"`
192193
Service *Service `json:"service"`
193194
Deployment *Deployment `json:"deployment,omitempty"`

web/src/components/env/env.jsx

+16-17
Original file line numberDiff line numberDiff line change
@@ -74,32 +74,31 @@ function renderServices(
7474
let configsWeDeployed = [];
7575
// render services that are deployed on k8s
7676
services = filteredStacks.map((stack) => {
77-
configsWeDeployed.push(stack.service.name);
78-
const configExists = configsWeHave.includes(stack.service.name)
79-
let config = undefined;
80-
if (configExists) {
77+
let config = envConfigs.find((config) => config.app === stack.app);
78+
if (!config) {
8179
config = envConfigs.find((config) => config.app === stack.service.name)
8280
}
81+
configsWeDeployed.push(config.app);
8382

8483
let deployment = "";
8584
if (stack.deployment) {
8685
deployment = stack.deployment.namespace + "/" + stack.deployment.name
8786
}
8887

88+
const appOrServiceName = config ? config.app : stack.service.name
8989
return (
90-
<div key={'sc-'+stack.service.name} className="w-full flex items-center justify-between space-x-6 p-4 card">
90+
<div key={'sc-'+appOrServiceName} className="w-full flex items-center justify-between space-x-6 p-4 card">
9191
<ServiceDetail
92-
key={'sc-'+stack.service.name}
92+
key={'sc-'+appOrServiceName}
9393
stack={stack}
94-
rolloutHistory={repoRolloutHistory?.[environment.name]?.[stack.service.name]}
94+
rolloutHistory={repoRolloutHistory?.[environment.name]?.[appOrServiceName]}
9595
rollback={rollback}
9696
environment={environment}
9797
owner={owner}
9898
repoName={repoName}
99-
fileName={fileName(fileInfos, stack.service.name)}
99+
fileName={fileName(fileInfos, appOrServiceName)}
100100
navigateToConfigEdit={navigateToConfigEdit}
101101
linkToDeployment={linkToDeployment}
102-
configExists={configExists}
103102
config={config}
104103
releaseHistorySinceDays={releaseHistorySinceDays}
105104
gimletClient={gimletClient}
@@ -117,27 +116,27 @@ function renderServices(
117116
}
118117

119118
const configsWeHaventDeployed = configsWeHave.filter(config => !configsWeDeployed.includes(config) && config.includes(appFilter));
120-
121119
services.push(
122-
...configsWeHaventDeployed.sort().map(config => {
120+
...configsWeHaventDeployed.sort().map(configName => {
121+
const config = envConfigs.find((config) => config.app === configName)
123122
return (
124-
<div key={config} className="w-full flex items-center justify-between space-x-6 p-4 pb-8 card">
123+
<div key={configName} className="w-full flex items-center justify-between space-x-6 p-4 pb-8 card">
125124
<ServiceDetail
126-
key={config}
125+
key={configName}
127126
stack={{
128127
service: {
129-
name: config
128+
name: configName
130129
}
131130
}}
132-
rolloutHistory={repoRolloutHistory?.[environment.name]?.[config]}
131+
rolloutHistory={repoRolloutHistory?.[environment.name]?.[configName]}
133132
rollback={rollback}
134133
environment={environment}
135134
owner={owner}
136135
repoName={repoName}
137-
fileName={fileName(fileInfos, config)}
136+
fileName={fileName(fileInfos, configName)}
138137
navigateToConfigEdit={navigateToConfigEdit}
139138
linkToDeployment={linkToDeployment}
140-
configExists={true}
139+
config={config}
141140
releaseHistorySinceDays={releaseHistorySinceDays}
142141
gimletClient={gimletClient}
143142
store={store}

web/src/components/serviceDetail/serviceDetail.jsx

+26-20
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ function ServiceDetail(props) {
2121
const { store, gimletClient } = props;
2222
const { owner, repoName } = props;
2323
const { environment } = props;
24-
const { stack, rolloutHistory, rollback, navigateToConfigEdit, linkToDeployment, configExists, config, fileName, releaseHistorySinceDays, deploymentFromParams, scmUrl, serviceAlerts } = props;
24+
const { stack, rolloutHistory, rollback, navigateToConfigEdit, linkToDeployment, config, fileName, releaseHistorySinceDays, deploymentFromParams, scmUrl, serviceAlerts } = props;
2525
const ref = useRef(null);
2626
const posthog = usePostHog()
2727
const [pullRequests, setPullRequests] = useState()
2828

2929
const progressToastId = useRef(null);
3030

31+
const configExists = config !== undefined
32+
3133
useEffect(() => {
3234
if (deploymentFromParams === stack.service.name) {
3335
window.scrollTo({ behavior: 'smooth', top: ref.current.offsetTop })
@@ -36,23 +38,25 @@ function ServiceDetail(props) {
3638
}, [deploymentFromParams, stack.service.name]);
3739

3840
useEffect(() => {
39-
gimletClient.getRolloutHistoryPerApp(owner, repoName, environment.name, stack.service.name)
40-
.then(data => {
41-
store.dispatch({
42-
type: ACTION_TYPE_ROLLOUT_HISTORY, payload: {
43-
owner: owner,
44-
repo: repoName,
45-
env: environment.name,
46-
app: stack.service.name,
47-
releases: data,
48-
}
49-
});
50-
}, () => {/* Generic error handler deals with it */ });
51-
52-
gimletClient.getConfigChangePullRequestsPerConfig(owner, repoName, environment.name, stack.service.name)
53-
.then(data => {
54-
setPullRequests(data)
55-
})
41+
if (config) {
42+
gimletClient.getRolloutHistoryPerApp(owner, repoName, environment.name, config.app)
43+
.then(data => {
44+
store.dispatch({
45+
type: ACTION_TYPE_ROLLOUT_HISTORY, payload: {
46+
owner: owner,
47+
repo: repoName,
48+
env: environment.name,
49+
app: config.app,
50+
releases: data,
51+
}
52+
});
53+
}, () => {/* Generic error handler deals with it */ });
54+
55+
gimletClient.getConfigChangePullRequestsPerConfig(owner, repoName, environment.name, config.app)
56+
.then(data => {
57+
setPullRequests(data)
58+
})
59+
}
5660
// eslint-disable-next-line react-hooks/exhaustive-deps
5761
}, []);
5862

@@ -194,7 +198,7 @@ function ServiceDetail(props) {
194198
onClick={() => {
195199
if (configExists) {
196200
posthog?.capture('Env config edit pushed')
197-
navigateToConfigEdit(environment.name, stack.service.name)
201+
navigateToConfigEdit(environment.name, config.app)
198202
}
199203
}}
200204
>
@@ -345,12 +349,13 @@ function ServiceDetail(props) {
345349
</div>
346350
</div>
347351
}
352+
{config &&
348353
<div>
349354
<p className="serviceCardLabel">Deploy History</p>
350355
<div className="text-neutral-900 text-sm pt-2">
351356
<RolloutHistory
352357
env={environment.name}
353-
app={stack.service.name}
358+
app={config.app}
354359
rollback={rollback}
355360
appRolloutHistory={rolloutHistory}
356361
releaseHistorySinceDays={releaseHistorySinceDays}
@@ -359,6 +364,7 @@ function ServiceDetail(props) {
359364
/>
360365
</div>
361366
</div>
367+
}
362368
</div>
363369
</div>
364370
</div>

0 commit comments

Comments
 (0)