Skip to content

Commit adf2f61

Browse files
Merge branch 'main' into release-bot
2 parents aa60dca + 7b8bac7 commit adf2f61

File tree

7 files changed

+307
-16
lines changed

7 files changed

+307
-16
lines changed

api/helm-app/service/HelmAppService.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,12 @@ func (impl *HelmAppServiceImpl) appListRespProtoTransformer(deployedApps *gRPC.D
11591159
}
11601160
// end
11611161
lastDeployed := deployedapp.LastDeployed.AsTime()
1162-
appDetails, appFetchErr := impl.appRepository.FindActiveByName(deployedapp.AppName)
1162+
appDetails, appFetchErr := impl.getAppForAppIdentifier(
1163+
&helmBean.AppIdentifier{
1164+
ClusterId: int(deployedapp.EnvironmentDetail.ClusterId),
1165+
Namespace: deployedapp.EnvironmentDetail.Namespace,
1166+
ReleaseName: deployedapp.AppName,
1167+
})
11631168
projectId := int32(0)
11641169
if appFetchErr == nil {
11651170
projectId = int32(appDetails.TeamId)

docs/reference/glossary.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ An immutable blob of data generated as an output after the execution of a job, b
1010

1111
* Once a job is complete, you can view the job artifacts by going to Jobs → Run history (tab) → (choose a pipeline and date of triggering the build) → Artifacts (tab).
1212

13+
### ArgoCD Apps
14+
15+
ArgoCD Apps are the micro-services deployed using a [GitOps](#gitops) deployment tool named [Argo CD](https://argo-cd.readthedocs.io/en/stable/).
16+
17+
If ArgoCD applications are present in your cluster, they will appear in the [ArgoCD Apps listing](../user-guide/applications.md#enabling-argocd-app-listing).
18+
1319
### Base Deployment Template
1420

1521
A deployment template is a manifest of the application defining its runtime behavior. You can select one of the default deployment charts or custom deployment charts created by super-admin.
@@ -112,6 +118,12 @@ Similarly, the CPU and memory resources can be different for each environment. T
112118

113119
You can add external links related to the application. For e.g., you can add Prometheus, Grafana, and many more to your application by going to Global Configurations → External Links. [Read More...](../user-guide/global-configurations/external-links.md)
114120

121+
### FluxCD Apps
122+
123+
FluxCD Apps are the micro-services deployed using a [GitOps](#gitops) deployment tool named [Flux CD](https://fluxcd.io/).
124+
125+
If FluxCD applications are present in your cluster, they will appear in the [FluxCD Apps listing](../user-guide/applications.md#view-fluxcd-app-listing).
126+
115127
### GitOps
116128

117129
A methodology for managing and automating Kubernetes deployments using Git repositories as the source of truth. Changes to the desired state of the cluster are driven by Git commits. [Read More...](../user-guide/global-configurations/gitops.md)

docs/user-guide/applications.md

Lines changed: 143 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,145 @@
11
# Applications
22

3-
Please configure Global Configurations before creating an application or cloning an existing application.
3+
{% hint style="warning" %}
4+
Configure [Global Configurations](./global-configurations/README.md) first before creating an application or cloning an existing application.
5+
{% endhint %}
6+
7+
## Introduction
8+
9+
The **Applications** page helps you create and manage your microservices, and it majorly consists of the following:
10+
11+
* [Application Listing](#application-listing)
12+
* [Create Button](#create-button)
13+
* [Other Options](#other-options)
14+
15+
### Application Listing
16+
17+
You can view the app name, its status, environment, namespace, and many more upfront. The apps are segregated into: [Devtron Apps](../reference/glossary.md#devtron-apps), [Helm Apps](../reference/glossary.md#helm-apps), [ArgoCD Apps](../reference/glossary.md#argocd-apps), and [FluxCD Apps](../reference/glossary.md#fluxcd-apps).
18+
19+
![Figure 1: App Types](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/argocd/app-types.jpg)
20+
21+
### Create Button
22+
23+
You can use this to:
24+
* [Create a Devtron app](./create-application.md)
25+
* [Create a Helm app](./deploy-chart/deployment-of-charts.md)
26+
* [Create a Job](./jobs/create-job.md)
27+
28+
### Other Options
29+
30+
There are additional options available for you:
31+
* **Search and filters** to make it easier for you to find applications.
32+
* **Export CSV** to download the data of Devtron apps (not supported for Helm apps and Argo CD apps).
33+
* **Sync button** to refresh the app listing.
34+
35+
---
36+
37+
## View ArgoCD App Listing
38+
39+
{% hint style="warning" %}
40+
### Who Can Perform This Action?
41+
Users need super-admin permission to view/enable/disable the ArgoCD listing.
42+
{% endhint %}
43+
44+
### Preface
45+
46+
In Argo CD, a user manages one dashboard for one ArgoCD instance. Therefore, with multiple ArgoCD instances, the process becomes cumbersome for the user to manage several dashboards.
47+
48+
With Devtron, you get an entire Argo CD app listing in one place. This listing includes:
49+
* Apps deployed using [GitOps](../reference/glossary.md#gitops) on Devtron
50+
* Other Argo CD apps present in your cluster
51+
52+
![Figure 2: ArgoCD App List](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/argocd/app-details-argo.gif)
53+
54+
### Advantages
55+
56+
Devtron also bridges the gap for ArgoCD users by providing additional features as follows:
57+
58+
* **Resource Scanning**: You can scan for vulnerabilities using Devtron's [resource scanning](../user-guide/security-features.md#from-app-details) feature. [![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/elements/EnterpriseTag.svg)](https://devtron.ai/pricing)
59+
60+
* **Single-pane View**: All Argo CD apps will show details such as their app status, environment, cluster, and namespace together in one dashboard.
61+
62+
* **Feature-rich Options**: Clicking an Argo CD app will give you access to its logs, terminal, events, manifest, available resource kinds, pod restart log, and many more.
63+
64+
{% hint style="info" %}
65+
### Additional References
66+
[ArgoCD: Standalone Configuration vs Devtron Configuration](https://devtron.ai/blog/argocd-standalone-configuration-vs-devtron-configuration/#argocd-installation-and-configuration)
67+
{% endhint %}
68+
69+
### Prerequisite
70+
The cluster in which Argo CD apps exist should be added in **Global Configurations****Clusters and Environments**
71+
72+
### Feature Flag
73+
74+
> **`ENABLE_EXTERNAL_ARGO_CD: "true"`**
75+
76+
### Enabling ArgoCD App Listing
77+
78+
{% embed url="https://www.youtube.com/watch?v=4KyYnsAEpqo" caption="Enabling External ArgoCD Listing" %}
79+
80+
1. Go to the **Resource Browser** of Devtron.
81+
82+
2. Select the cluster (in which your Argo CD app exists).
83+
84+
3. Type `ConfigMap` in the 'Jump to Kind' field.
85+
86+
4. Search for `dashboard-cm` using the available search bar and click it.
87+
88+
5. Click **Edit Live Manifest**.
89+
90+
6. Set the feature flag **ENABLE_EXTERNAL_ARGO_CD** to **"true"**
91+
92+
7. Click **Apply Changes**.
93+
94+
8. Go back to the 'Jump to Kind' field and type `Pod`.
95+
96+
9. Search for `dashboard` pod and use the kebab menu (3 vertical dots) to delete the pod.
97+
98+
10. Go to **Applications** and refresh the page. A new tab named **ArgoCD Apps** will be visible.
99+
100+
11. Select the cluster(s) from the dropdown to view the Argo CD apps available in the chosen cluster(s).
101+
102+
![Figure 3: Cluster Selection for Argo CD Listing](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/argocd/argo-cluster-selection.jpg)
103+
104+
---
105+
106+
## View FluxCD App Listing
107+
108+
{% hint style="warning" %}
109+
### Who Can Perform This Action?
110+
Users need super-admin permission to view/enable/disable the FluxCD listing.
111+
{% endhint %}
112+
113+
### Preface
114+
115+
Flux CD doesn't have any official dashboard; however, Devtron supports the listing of your [Flux CD](https://fluxcd.io/) apps in one dashboard. Here, the [advantages](#advantages) are same as those of [ArgoCD app listing](#view-argocd-app-listing).
116+
117+
![Figure 4: FluxCD App List and Details](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/fluxcd/fluxcd-listing.jpg)
118+
119+
### Prerequisite
120+
The cluster in which Flux CD apps exist should be added in **Global Configurations****Clusters and Environments**
121+
122+
### Feature Flag
123+
124+
> **`FEATURE_EXTERNAL_FLUX_CD_ENABLE: "true"`**
125+
126+
### Enabling FluxCD App Listing
127+
128+
{% hint style="info" %}
129+
### Tip
130+
You may refer the steps mentioned in the [Enabling ArgoCD App Listing](#enabling-argocd-app-listing) section since the procedure is similar.
131+
{% endhint %}
132+
133+
Using Devtron's Resource Browser, add the [feature flag](#feature-flag-1) in the Dashboard ConfigMap as shown below.
134+
135+
![Figure 5: Editing Dashboard ConfigMap](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/fluxcd/flux-feature-flag.jpg)
136+
137+
After successfully executing all the steps, a new tab named **FluxCD Apps** will be visible. Select the cluster(s) from the dropdown to view the Flux CD apps available in the chosen cluster(s).
138+
139+
![Figure 6: Selecting Cluster](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/fluxcd/cluster-selection.jpg)
140+
141+
(Optional) Once you choose cluster(s), you may use the **Template Type** dropdown to further filter your Flux CD app listing based on its type, i.e., [Kustomization](https://fluxcd.io/flux/components/kustomize/kustomizations/) or [Helmrelease](https://fluxcd.io/flux/components/helm/helmreleases/).
142+
143+
Click any Flux CD app to view its details as shown below.
144+
145+
![Figure 7: Flux App Details](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/fluxcd/app-details-flux.gif)

docs/user-guide/global-configurations/filter-condition.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Using filter conditions, you can control the progression of events. Here are a f
88
* Images containing the label "test" should not be eligible for deployment in production environment
99
* Only images having tag versions greater than v0.7.4 should be eligible for deployment
1010
* Images hosted on Docker Hub should be eligible but not the rest
11+
* Only images derived from master branch should be eligible for production deployment (see [example](#scenario-2))
1112

1213
---
1314

@@ -55,17 +56,17 @@ You must have application(s) with CI-CD workflow(s) configured
5556

5657
![Figure 5: Selecting Environment(s) from Cluster(s)](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/global-configurations/filters/environment-selection.jpg)
5758

58-
{% hint style="info" %}
59-
Since an application can have more than one environment, the filter conditions apply only to the environment you chose in the **Apply to** section. If you create a filter condition without choosing an application or environment, it will not apply to any of your pipelines.
60-
{% endhint %}
59+
{% hint style="info" %}
60+
Since an application can have more than one environment, the filter conditions apply only to the environment you chose in the **Apply to** section. If you create a filter condition without choosing an application or environment, it will not apply to any of your pipelines.
61+
{% endhint %}
6162

6263
6. Click **Save**. You have successfully created a filter.
6364

6465
![Figure 6: Success Toast](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/global-configurations/filters/filter-created.jpg)
6566

66-
{% hint style="warning" %}
67-
If you create filters using CEL expressions that result in a conflict (i.e., passing and failing of the same image), fail will have higher precedence
68-
{% endhint %}
67+
{% hint style="warning" %}
68+
If you create filters using CEL expressions that result in a conflict (i.e., passing and failing of the same image), fail will have higher precedence
69+
{% endhint %}
6970

7071
---
7172

@@ -78,6 +79,8 @@ Here's a sample pipeline we will be using for our explanation of [pass condition
7879

7980
### Pass Condition
8081

82+
#### Scenario 1
83+
8184
Consider a scenario where you wish to make an image eligible for deployment only if its tag version is greater than `v0.0.7`
8285

8386
The CEL Expression should be `containerImageTag > "v0.0.7"`
@@ -102,6 +105,25 @@ Clicking the filter icon at the top-left shows the filter condition(s) applied t
102105

103106
![Figure 12b: Conditions Applied](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/global-configurations/filters/conditions-applied-1.jpg)
104107

108+
#### Scenario 2
109+
110+
Consider another scenario where you wish to make images eligible for deployment only if the application's git branch starts with the word `hotfix` and also if its repo URL matches your specified condition.
111+
112+
**CEL Expression**:
113+
114+
`gitCommitDetails.filter(gitCommitDetail, gitCommitDetail.startsWith('https://github.com/devtron-labs')).map(repo, gitCommitDetails[repo].branch).exists_one(branch, branch.startsWith('hotfix-'))`
115+
116+
where, `https://github.com/devtron-labs` is a portion of the repo URL <br />
117+
and `hotfix-` is for finding the branch name (say *hotfix-sept-2024*)
118+
119+
Alternatively, if you have a fixed branch (say *hotfix-123*), you may write the following expression:
120+
121+
`'hotfix-123' in gitCommitDetails.filter(gitCommitDetail, gitCommitDetail.startsWith('https://github.com/devtron-labs')).map(repo, gitCommitDetails[repo].branch)`
122+
123+
**Walkthrough Video**:
124+
125+
{% embed url="https://www.youtube.com/watch?v=R8IbZhXhH-k" caption="Filter Condition Example" %}
126+
105127

106128
### Fail Condition
107129

internal/sql/repository/app/AppRepository.go

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ type App struct {
4040
sql.AuditLog
4141
}
4242

43+
const (
44+
SYSTEM_USER_ID = 1
45+
)
46+
4347
func (r *App) IsAppJobOrExternalType() bool {
4448
return len(r.DisplayName) > 0
4549
}
@@ -129,16 +133,37 @@ func (repo AppRepositoryImpl) SetDescription(id int, description string, userId
129133
}
130134

131135
func (repo AppRepositoryImpl) FindActiveByName(appName string) (*App, error) {
132-
pipelineGroup := &App{}
136+
var apps []*App
133137
err := repo.dbConnection.
134-
Model(pipelineGroup).
138+
Model(&apps).
135139
Where("app_name = ?", appName).
136140
Where("active = ?", true).
137-
Order("id DESC").Limit(1).
141+
Order("id DESC").
138142
Select()
139-
// there is only single active app will be present in db with a same name.
140-
return pipelineGroup, err
143+
if len(apps) == 1 {
144+
return apps[0], nil
145+
} else if len(apps) > 1 {
146+
isHelmApp := true
147+
for _, app := range apps {
148+
if app.AppType != helper.ChartStoreApp && app.AppType != helper.ExternalChartStoreApp {
149+
isHelmApp = false
150+
break
151+
}
152+
}
153+
if isHelmApp {
154+
err := repo.fixMultipleHelmAppsWithSameName(appName)
155+
if err != nil {
156+
repo.logger.Errorw("error in fixing duplicate helm apps with same name")
157+
return nil, err
158+
}
159+
}
160+
return apps[0], nil
161+
} else {
162+
err = pg.ErrNoRows
163+
}
164+
return nil, err
141165
}
166+
142167
func (repo AppRepositoryImpl) FindAppIdByName(appName string) (int, error) {
143168
app := &App{}
144169
err := repo.dbConnection.
@@ -324,9 +349,52 @@ func (repo AppRepositoryImpl) FindAppAndProjectByAppName(appName string) (*App,
324349
Where("app.app_name = ?", appName).
325350
Where("app.active=?", true).
326351
Select()
352+
353+
if err == pg.ErrMultiRows && (app.AppType == helper.ChartStoreApp || app.AppType == helper.ExternalChartStoreApp) {
354+
// this case can arise in helms apps only
355+
356+
err := repo.fixMultipleHelmAppsWithSameName(appName)
357+
if err != nil {
358+
repo.logger.Errorw("error in fixing duplicate helm apps with same name")
359+
return nil, err
360+
}
361+
362+
err = repo.dbConnection.Model(app).Column("Team").
363+
Where("app.app_name = ?", appName).
364+
Where("app.active=?", true).
365+
Select()
366+
if err != nil {
367+
repo.logger.Errorw("error in fetching apps by name", "appName", appName, "err", err)
368+
return nil, err
369+
}
370+
}
327371
return app, err
328372
}
329373

374+
func (repo AppRepositoryImpl) fixMultipleHelmAppsWithSameName(appName string) error {
375+
// updating installed apps setting app_id = max app_id
376+
installAppUpdateQuery := `update installed_apps set
377+
app_id=(select max(id) as id from app where app_name = ?)
378+
where app_id in (select id from app where app_name= ? )`
379+
380+
_, err := repo.dbConnection.Exec(installAppUpdateQuery, appName, appName)
381+
if err != nil {
382+
repo.logger.Errorw("error in updating maxAppId in installedApps", "appName", appName, "err", err)
383+
return err
384+
}
385+
386+
maxAppIdQuery := repo.dbConnection.Model((*App)(nil)).ColumnExpr("max(id)").
387+
Where("app_name = ? ", appName).
388+
Where("active = ? ", true)
389+
390+
// deleting all apps other than app with max id
391+
_, err = repo.dbConnection.Model((*App)(nil)).
392+
Set("active = ?", false).Set("updated_by = ?", SYSTEM_USER_ID).Set("updated_on = ?", time.Now()).
393+
Where("id not in (?) ", maxAppIdQuery).Update()
394+
395+
return nil
396+
}
397+
330398
func (repo AppRepositoryImpl) FindAllMatchesByAppName(appName string, appType helper.AppType) ([]*App, error) {
331399
var apps []*App
332400
var err error

0 commit comments

Comments
 (0)