Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alexy appset resource tree #7

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
db3f2dd
initial refactoring
reggie-k Sep 29, 2023
5202333
initial linting and fromAppComponents=false
reggie-k Sep 29, 2023
ff93e4c
initial linting and isInvokedFromApp=false
reggie-k Sep 29, 2023
dfd6642
upstream sync
reggie-k Sep 29, 2023
c6017bd
Merge branch 'argoproj:master' into master
reggie-k Oct 4, 2023
19c5c08
disable delete for AppSets
reggie-k Oct 4, 2023
edaab01
upstream sync
reggie-k Nov 18, 2023
9e1acf0
regression fix
reggie-k Nov 18, 2023
f7a17a1
fixed formatting
reggie-k Nov 26, 2023
ed3d8ce
fixed formatting
reggie-k Nov 26, 2023
c579e35
cleanup
reggie-k Nov 26, 2023
668bdb5
support appset-resource-tree
reggie-k Nov 26, 2023
c6a167a
atempt to maximize isApp and isInvokedFromAppsCtx
reggie-k Nov 26, 2023
6dd506b
attempt to maximize isApp and isInvokedFromAppsCtx
reggie-k Nov 30, 2023
687b455
attempt to maximize isApp and isInvokedFromAppsCtx
reggie-k Nov 30, 2023
253a432
useContext in some more places and improve dynamicity
reggie-k Dec 2, 2023
35de291
linting fixes in ctx and abstract objects reference
reggie-k Dec 2, 2023
e72c302
linting fixes in ctx and abstract objects reference
reggie-k Dec 2, 2023
38cac5d
attempt to fix the tests
reggie-k Dec 3, 2023
905f93d
attempt to fix the tests
reggie-k Dec 3, 2023
c4ab34e
change how the AppSet health is calculated
reggie-k Dec 3, 2023
c8d09d7
master sync
reggie-k Dec 3, 2023
157a845
fixed AppSet health status bar and added its statuses to css
reggie-k Dec 3, 2023
b1ae7f1
update types
alexymantha Dec 9, 2023
0a1b1d9
Update generated code
alexymantha Dec 9, 2023
302c157
wip
alexymantha Dec 9, 2023
64df708
add resource tree
alexymantha Dec 9, 2023
5c606e4
Update generated code
alexymantha Dec 9, 2023
499aa6c
fix
alexymantha Dec 9, 2023
0e57acf
cleanup
alexymantha Dec 9, 2023
84b2e6f
format
alexymantha Dec 9, 2023
384a871
fix lint
alexymantha Dec 9, 2023
b3984e5
Merge branch 'appset-resource-tree' of https://github.com/alexymantha…
reggie-k Dec 14, 2023
7495c7f
ResourceStatus for resource tree changes
reggie-k Dec 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 85 additions & 7 deletions applicationset/controllers/applicationset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@
return ctrl.Result{RequeueAfter: ReconcileRequeueOnValidationError}, nil
}

currentApplications, err := r.getCurrentApplications(ctx, applicationSetInfo)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to get current applications for application set: %w", err)
}

err = r.updateResourcesStatus(ctx, logCtx, &applicationSetInfo, currentApplications)

Check failure on line 171 in applicationset/controllers/applicationset_controller.go

View workflow job for this annotation

GitHub Actions / Lint Go code

File is not `gofmt`-ed with `-s` (gofmt)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to get update resources status for application set: %w", err)
}

// appMap is a name->app collection of Applications in this ApplicationSet.
appMap := map[string]argov1alpha1.Application{}
// appSyncMap tracks which apps will be synced during this reconciliation.
Expand All @@ -179,16 +189,11 @@
}
} else if applicationSetInfo.Spec.Strategy != nil {
// appset uses progressive sync
applications, err := r.getCurrentApplications(ctx, applicationSetInfo)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to get current applications for application set: %w", err)
}

for _, app := range applications {
for _, app := range currentApplications {
appMap[app.Name] = app
}

appSyncMap, err = r.performProgressiveSyncs(ctx, logCtx, applicationSetInfo, applications, desiredApplications, appMap)
appSyncMap, err = r.performProgressiveSyncs(ctx, logCtx, applicationSetInfo, currentApplications, desiredApplications, appMap)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to perform progressive sync reconciliation for application set: %w", err)
}
Expand Down Expand Up @@ -1349,6 +1354,79 @@
return -1
}

func (r *ApplicationSetReconciler) updateResourcesStatus(ctx context.Context, logCtx *log.Entry, appset *argov1alpha1.ApplicationSet, apps []argov1alpha1.Application) error {
statusMap := getResourceStatusMap(appset)
statusMap = buildResourceStatus(statusMap, apps)

statuses := []argov1alpha1.ResourceStatus{}
for _, status := range statusMap {
statuses = append(statuses, status)
}
appset.Status.Resources = statuses

namespacedName := types.NamespacedName{Namespace: appset.Namespace, Name: appset.Name}
err := r.Client.Status().Update(ctx, appset)
if err != nil {

logCtx.Errorf("unable to set application set status: %v", err)
return fmt.Errorf("unable to set application set status: %v", err)
}

if err := r.Get(ctx, namespacedName, appset); err != nil {
if client.IgnoreNotFound(err) != nil {
return nil
}
return fmt.Errorf("error fetching updated application set: %v", err)
}

return nil
}

func buildResourceStatus(statusMap map[string]argov1alpha1.ResourceStatus, apps []argov1alpha1.Application) map[string]argov1alpha1.ResourceStatus {
appMap := map[string]argov1alpha1.Application{}
for _, app := range apps {
appCopy := app
appMap[app.Name] = app

// Create status if it does not exist
status, ok := statusMap[app.Name]
if !ok {
status = argov1alpha1.ResourceStatus{
Name: app.Name,
Namespace: app.Namespace,
Status: app.Status.Sync.Status,
Health: &appCopy.Status.Health,
}
}

status.Name = app.Name
status.Namespace = app.Namespace
status.Status = app.Status.Sync.Status
status.Health = &appCopy.Status.Health

statusMap[app.Name] = status
}
cleanupDeletedApplicationStatuses(statusMap, appMap)

return statusMap
}

func getResourceStatusMap(appset *argov1alpha1.ApplicationSet) map[string]argov1alpha1.ResourceStatus {
statusMap := map[string]argov1alpha1.ResourceStatus{}
for _, status := range appset.Status.Resources {
statusMap[status.Name] = status
}
return statusMap
}

func cleanupDeletedApplicationStatuses(statusMap map[string]argov1alpha1.ResourceStatus, apps map[string]argov1alpha1.Application) {
for name := range statusMap {
if _, ok := apps[name]; !ok {
delete(statusMap, name)
}
}
}

// setApplicationSetApplicationStatus updates the ApplicatonSet's status field
// with any new/changed Application statuses.
func (r *ApplicationSetReconciler) setAppSetApplicationStatus(ctx context.Context, logCtx *log.Entry, applicationSet *argov1alpha1.ApplicationSet, applicationStatuses []argov1alpha1.ApplicationSetApplicationStatus) error {
Expand Down
57 changes: 57 additions & 0 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,43 @@
}
}
},
"/api/v1/applicationsets/{name}/resource-tree": {
"get": {
"tags": [
"ApplicationSetService"
],
"summary": "ResourceTree returns resource tree",
"operationId": "ApplicationSetService_ResourceTree",
"parameters": [
{
"type": "string",
"name": "name",
"in": "path",
"required": true
},
{
"type": "string",
"description": "The application set namespace. Default empty is argocd control plane namespace.",
"name": "appsetNamespace",
"in": "query"
}
],
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1alpha1ApplicationSetTree"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/runtimeError"
}
}
}
}
},
"/api/v1/certificates": {
"get": {
"tags": [
Expand Down Expand Up @@ -6165,6 +6202,13 @@
"items": {
"$ref": "#/definitions/v1alpha1ApplicationSetCondition"
}
},
"resources": {
"description": "Resources is a list of Applications resources managed by this application set.",
"type": "array",
"items": {
"$ref": "#/definitions/v1alpha1ResourceStatus"
}
}
}
},
Expand Down Expand Up @@ -6236,6 +6280,19 @@
}
}
},
"v1alpha1ApplicationSetTree": {
"type": "object",
"title": "ApplicationSetTree holds nodes which belongs to the application\nUsed to build a tree of an ApplicationSet and its children",
"properties": {
"nodes": {
"type": "array",
"title": "Nodes contains list of nodes which are directly managed by the applicationset",
"items": {
"$ref": "#/definitions/v1alpha1ResourceNode"
}
}
}
},
"v1alpha1ApplicationSource": {
"type": "object",
"title": "ApplicationSource contains all required information about the source of an application",
Expand Down
31 changes: 31 additions & 0 deletions manifests/core-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20173,6 +20173,37 @@ spec:
- type
type: object
type: array
resources:
items:
properties:
group:
type: string
health:
properties:
message:
type: string
status:
type: string
type: object
hook:
type: boolean
kind:
type: string
name:
type: string
namespace:
type: string
requiresPruning:
type: boolean
status:
type: string
syncWave:
format: int64
type: integer
version:
type: string
type: object
type: array
type: object
required:
- metadata
Expand Down
31 changes: 31 additions & 0 deletions manifests/crds/applicationset-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15233,6 +15233,37 @@ spec:
- type
type: object
type: array
resources:
items:
properties:
group:
type: string
health:
properties:
message:
type: string
status:
type: string
type: object
hook:
type: boolean
kind:
type: string
name:
type: string
namespace:
type: string
requiresPruning:
type: boolean
status:
type: string
syncWave:
format: int64
type: integer
version:
type: string
type: object
type: array
type: object
required:
- metadata
Expand Down
31 changes: 31 additions & 0 deletions manifests/ha/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20173,6 +20173,37 @@ spec:
- type
type: object
type: array
resources:
items:
properties:
group:
type: string
health:
properties:
message:
type: string
status:
type: string
type: object
hook:
type: boolean
kind:
type: string
name:
type: string
namespace:
type: string
requiresPruning:
type: boolean
status:
type: string
syncWave:
format: int64
type: integer
version:
type: string
type: object
type: array
type: object
required:
- metadata
Expand Down
31 changes: 31 additions & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20173,6 +20173,37 @@ spec:
- type
type: object
type: array
resources:
items:
properties:
group:
type: string
health:
properties:
message:
type: string
status:
type: string
type: object
hook:
type: boolean
kind:
type: string
name:
type: string
namespace:
type: string
requiresPruning:
type: boolean
status:
type: string
syncWave:
format: int64
type: integer
version:
type: string
type: object
type: array
type: object
required:
- metadata
Expand Down
Loading
Loading