Skip to content

Commit

Permalink
feat: Add controllerNamespace to .status of an application (argoproj#…
Browse files Browse the repository at this point in the history
…13081)

Signed-off-by: Kevin Huber <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]>
  • Loading branch information
ItsKev and crenshaw-dev authored May 27, 2023
1 parent dfa11ae commit 032a596
Show file tree
Hide file tree
Showing 11 changed files with 733 additions and 622 deletions.
4 changes: 4 additions & 0 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6345,6 +6345,10 @@
"$ref": "#/definitions/v1alpha1ApplicationCondition"
}
},
"controllerNamespace": {
"type": "string",
"title": "ControllerNamespace indicates the namespace in which the application controller is located"
},
"health": {
"$ref": "#/definitions/v1alpha1HealthStatus"
},
Expand Down
1 change: 1 addition & 0 deletions controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,7 @@ func (ctrl *ApplicationController) processAppRefreshQueueItem() (processNext boo
})
app.Status.SourceType = compareResult.appSourceType
app.Status.SourceTypes = compareResult.appSourceTypes
app.Status.ControllerNamespace = ctrl.namespace
ctrl.persistAppStatus(origApp, &app.Status)
return
}
Expand Down
38 changes: 37 additions & 1 deletion controller/appcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type fakeData struct {
namespacedResources map[kube.ResourceKey]namespacedResource
configMapData map[string]string
metricsCacheExpiration time.Duration
applicationNamespaces []string
}

func newFakeController(data *fakeData) *ApplicationController {
Expand Down Expand Up @@ -111,7 +112,7 @@ func newFakeController(data *fakeData) *ApplicationController {
0,
true,
nil,
[]string{},
data.applicationNamespaces,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -1584,3 +1585,38 @@ func Test_syncDeleteOption(t *testing.T) {
assert.False(t, delete)
})
}

func TestAddControllerNamespace(t *testing.T) {
t.Run("set controllerNamespace when the app is in the controller namespace", func(t *testing.T) {
app := newFakeApp()
ctrl := newFakeController(&fakeData{
apps: []runtime.Object{app, &defaultProj},
manifestResponse: &apiclient.ManifestResponse{},
})

ctrl.processAppRefreshQueueItem()

updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(ctrl.namespace).Get(context.Background(), app.Name, metav1.GetOptions{})
assert.NoError(t, err)
assert.Equal(t, test.FakeArgoCDNamespace, updatedApp.Status.ControllerNamespace)
})
t.Run("set controllerNamespace when the app is in another namespace than the controller", func(t *testing.T) {
appNamespace := "app-namespace"

app := newFakeApp()
app.ObjectMeta.Namespace = appNamespace
proj := defaultProj
proj.Spec.SourceNamespaces = []string{appNamespace}
ctrl := newFakeController(&fakeData{
apps: []runtime.Object{app, &proj},
manifestResponse: &apiclient.ManifestResponse{},
applicationNamespaces: []string{appNamespace},
})

ctrl.processAppRefreshQueueItem()

updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(appNamespace).Get(context.Background(), app.Name, metav1.GetOptions{})
assert.NoError(t, err)
assert.Equal(t, test.FakeArgoCDNamespace, updatedApp.Status.ControllerNamespace)
})
}
4 changes: 4 additions & 0 deletions manifests/core-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,10 @@ spec:
- type
type: object
type: array
controllerNamespace:
description: ControllerNamespace indicates the namespace in which
the application controller is located
type: string
health:
description: Health contains information about the application's current
health status
Expand Down
4 changes: 4 additions & 0 deletions manifests/crds/application-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,10 @@ spec:
- type
type: object
type: array
controllerNamespace:
description: ControllerNamespace indicates the namespace in which
the application controller is located
type: string
health:
description: Health contains information about the application's current
health status
Expand Down
4 changes: 4 additions & 0 deletions manifests/ha/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,10 @@ spec:
- type
type: object
type: array
controllerNamespace:
description: ControllerNamespace indicates the namespace in which
the application controller is located
type: string
health:
description: Health contains information about the application's current
health status
Expand Down
4 changes: 4 additions & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,10 @@ spec:
- type
type: object
type: array
controllerNamespace:
description: ControllerNamespace indicates the namespace in which
the application controller is located
type: string
health:
description: Health contains information about the application's current
health status
Expand Down
Loading

0 comments on commit 032a596

Please sign in to comment.