Skip to content

Commit cfe519c

Browse files
authored
feat(plugins): add image extraction and revision image model to argocd (#8631)
Adds ArgocdRevisionImage model + migration, extractor fallback logic, tests, and Grafana panels for deployment image visibility; includes golangci-lint config. For the issue #8630
1 parent 9ec6714 commit cfe519c

File tree

11 files changed

+500
-8
lines changed

11 files changed

+500
-8
lines changed

backend/plugins/argocd/impl/impl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (p ArgoCD) GetTablesInfo() []dal.Tabler {
8585
&models.ArgocdConnection{},
8686
&models.ArgocdApplication{},
8787
&models.ArgocdSyncOperation{},
88+
&models.ArgocdRevisionImage{},
8889
&models.ArgocdScopeConfig{},
8990
}
9091
}

backend/plugins/argocd/models/application.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type ArgocdApplication struct {
3939
SyncStatus string `gorm:"type:varchar(100)" json:"syncStatus" mapstructure:"syncStatus"` // Synced, OutOfSync, Unknown
4040
HealthStatus string `gorm:"type:varchar(100)" json:"healthStatus" mapstructure:"healthStatus"` // Healthy, Progressing, Degraded, Suspended, Missing, Unknown
4141
CreatedDate *time.Time `json:"createdDate,omitempty" mapstructure:"createdDate,omitempty"`
42+
SummaryImages []string `gorm:"type:json;serializer:json" json:"summaryImages" mapstructure:"summaryImages"`
4243
common.NoPKModel
4344
}
4445

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package migrationscripts
19+
20+
import (
21+
"github.com/apache/incubator-devlake/core/context"
22+
"github.com/apache/incubator-devlake/core/errors"
23+
"github.com/apache/incubator-devlake/core/plugin"
24+
"github.com/apache/incubator-devlake/helpers/migrationhelper"
25+
"github.com/apache/incubator-devlake/plugins/argocd/models/migrationscripts/archived"
26+
)
27+
28+
var _ plugin.MigrationScript = (*addImageSupportArtifacts)(nil)
29+
30+
type addImageSupportArtifacts struct{}
31+
32+
func (m *addImageSupportArtifacts) Up(basicRes context.BasicRes) errors.Error {
33+
return migrationhelper.AutoMigrateTables(
34+
basicRes,
35+
&archived.ArgocdApplication{},
36+
&archived.ArgocdSyncOperation{},
37+
&archived.ArgocdRevisionImage{},
38+
)
39+
}
40+
41+
func (*addImageSupportArtifacts) Version() uint64 {
42+
return 20251102160000
43+
}
44+
45+
func (*addImageSupportArtifacts) Name() string {
46+
return "argocd add image support artifacts"
47+
}

backend/plugins/argocd/models/migrationscripts/archived/models.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type ArgocdApplication struct {
4747
SyncStatus string `gorm:"type:varchar(100)"`
4848
HealthStatus string `gorm:"type:varchar(100)"`
4949
CreatedDate *time.Time
50+
SummaryImages []string `gorm:"type:json;serializer:json"`
5051
ScopeConfigId uint64
5152
archived.NoPKModel
5253
}
@@ -69,13 +70,26 @@ type ArgocdSyncOperation struct {
6970
SyncStatus string `gorm:"type:varchar(100)"`
7071
HealthStatus string `gorm:"type:varchar(100)"`
7172
ResourcesCount int
73+
ContainerImages []string `gorm:"type:json;serializer:json"`
7274
archived.NoPKModel
7375
}
7476

7577
func (ArgocdSyncOperation) TableName() string {
7678
return "_tool_argocd_sync_operations"
7779
}
7880

81+
type ArgocdRevisionImage struct {
82+
ConnectionId uint64 `gorm:"primaryKey"`
83+
ApplicationName string `gorm:"primaryKey;type:varchar(255)"`
84+
Revision string `gorm:"primaryKey;type:varchar(255)"`
85+
Images []string `gorm:"type:json;serializer:json"`
86+
archived.NoPKModel
87+
}
88+
89+
func (ArgocdRevisionImage) TableName() string {
90+
return "_tool_argocd_revision_images"
91+
}
92+
7993
type ArgocdScopeConfig struct {
8094
archived.ScopeConfig `mapstructure:",squash" json:",inline" gorm:"embedded"`
8195
ConnectionId uint64 `gorm:"index"`

backend/plugins/argocd/models/migrationscripts/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ import (
2424
func All() []plugin.MigrationScript {
2525
return []plugin.MigrationScript{
2626
new(addInitTables),
27+
new(addImageSupportArtifacts),
2728
}
2829
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package models
19+
20+
import "github.com/apache/incubator-devlake/core/models/common"
21+
22+
// ArgocdRevisionImage captures the container images observed for a given
23+
// Argo CD application revision. It enables historical lookups so that
24+
// previously processed sync operations retain the images that were active
25+
// when they first ran, even after subsequent deployments update the
26+
// application summary images.
27+
type ArgocdRevisionImage struct {
28+
ConnectionId uint64 `gorm:"primaryKey"`
29+
ApplicationName string `gorm:"primaryKey;type:varchar(255)"`
30+
Revision string `gorm:"primaryKey;type:varchar(255)"`
31+
Images []string `gorm:"type:json;serializer:json"`
32+
common.NoPKModel
33+
}
34+
35+
func (ArgocdRevisionImage) TableName() string {
36+
return "_tool_argocd_revision_images"
37+
}

backend/plugins/argocd/models/sync_operation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type ArgocdSyncOperation struct {
3737
SyncStatus string `gorm:"type:varchar(100)"` // Synced, OutOfSync
3838
HealthStatus string `gorm:"type:varchar(100)"` // Healthy, Degraded, etc.
3939
ResourcesCount int
40+
ContainerImages []string `gorm:"type:json;serializer:json"`
4041
common.NoPKModel
4142
}
4243

backend/plugins/argocd/tasks/application_extractor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ type ArgocdApiApplication struct {
6363
Health struct {
6464
Status string `json:"status"` // Healthy, Progressing, Degraded, etc.
6565
} `json:"health"`
66+
Summary struct {
67+
Images []string `json:"images"`
68+
} `json:"summary"`
6669
} `json:"status"`
6770
}
6871

@@ -96,6 +99,7 @@ func ExtractApplications(taskCtx plugin.SubTaskContext) errors.Error {
9699
DestNamespace: apiApp.Spec.Destination.Namespace,
97100
SyncStatus: apiApp.Status.Sync.Status,
98101
HealthStatus: apiApp.Status.Health.Status,
102+
SummaryImages: apiApp.Status.Summary.Images,
99103
CreatedDate: &apiApp.Metadata.CreationTimestamp,
100104
}
101105
application.ConnectionId = data.Options.ConnectionId

0 commit comments

Comments
 (0)