Skip to content

Commit

Permalink
devdb: fixed pod conflict when the resource same has name cross ns (#191
Browse files Browse the repository at this point in the history
)
  • Loading branch information
giautm authored Oct 1, 2024
1 parent d77f526 commit a739b98
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
- name: Run e2e tests
run: |
make docker-build test-e2e \
ATLAS_TOKEN=${{ secrets.ATLAS_TOKEN }} \
IMG=ariga/atlas-operator:e2e \
KIND_CLUSTER=chart-testing
test:
Expand Down
25 changes: 15 additions & 10 deletions internal/controller/devdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func newDevDB(mgr Manager, r record.EventRecorder, prewarm bool) *devDBReconcile

// cleanUp clean up any resources created by the controller
func (r *devDBReconciler) cleanUp(ctx context.Context, sc client.Object) {
key := nameDevDB(sc)
// If prewarmDevDB is false, scale down the deployment to 0
if !r.prewarm {
deploy := &appsv1.Deployment{}
key := nameDevDB(sc)
err := r.Get(ctx, key, deploy)
if err != nil {
r.recorder.Eventf(sc, corev1.EventTypeWarning, "CleanUpDevDB", "Error getting devDB deployment: %v", err)
Expand All @@ -90,11 +90,14 @@ func (r *devDBReconciler) cleanUp(ctx context.Context, sc client.Object) {
}
// delete pods to clean up
pods := &corev1.PodList{}
err := r.List(ctx, pods, client.MatchingLabels(map[string]string{
labelInstance: nameDevDB(sc).Name,
}))
if err != nil {
if err := r.List(ctx, pods,
client.InNamespace(key.Namespace),
client.MatchingLabels(map[string]string{
labelInstance: key.Name,
}),
); err != nil {
r.recorder.Eventf(sc, corev1.EventTypeWarning, "CleanUpDevDB", "Error listing devDB pods: %v", err)
return
}
for _, p := range pods.Items {
if err := r.Delete(ctx, &p); err != nil {
Expand Down Expand Up @@ -146,11 +149,13 @@ func (r *devDBReconciler) devURL(ctx context.Context, sc client.Object, targetUR
return "", err
}
pods := &corev1.PodList{}
err := r.List(ctx, pods, client.MatchingLabels(map[string]string{
labelEngine: drv,
labelInstance: key.Name,
}))
switch {
switch err := r.List(ctx, pods,
client.InNamespace(key.Namespace),
client.MatchingLabels(map[string]string{
labelEngine: drv,
labelInstance: key.Name,
}),
); {
case err != nil:
return "", transient(err)
case len(pods.Items) == 0:
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func TestOperator(t *testing.T) {
Dir: filepath.Join("testdata", "atlas-schema"),
Setup: func(e *testscript.Env) (err error) {
e.Setenv("CONTROLLER", "deployment/atlas-operator-controller-manager")
// Sharing the atlas token with the test
e.Setenv("ATLAS_TOKEN", os.Getenv("ATLAS_TOKEN"))
// Ensure the test in running in the right kube context
e.Setenv("KUBECONFIG", kubeconfig)
// Creating a namespace for the test
Expand Down

0 comments on commit a739b98

Please sign in to comment.