-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for AgentConfig deletion
Signed-off-by: Yingrong Zhao <[email protected]>
- Loading branch information
Showing
4 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//go:build integration | ||
|
||
package integration_test | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo" | ||
"github.com/tidwall/gjson" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
porterv1 "get.porter.sh/operator/api/v1" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("AgentConfig delete", func() { | ||
Context("when an existing AgentConfig is delete", func() { | ||
It("should delete AgentConfig and remove owner reference from all volumes it's associated with", func() { | ||
By("creating an agent action", func() { | ||
ctx := context.Background() | ||
ns := createTestNamespace(ctx) | ||
|
||
agentCfg := NewTestAgentCfg() | ||
agentCfg.Namespace = ns | ||
|
||
Expect(k8sClient.Create(ctx, agentCfg)).Should(Succeed()) | ||
Expect(waitForPorter(ctx, agentCfg, 1, "waiting for plugins to be installed")).Should(Succeed()) | ||
validateResourceConditions(agentCfg) | ||
|
||
Log("verify it's created") | ||
jsonOut := runAgentAction(ctx, "create-check-plugins-list", ns, []string{"plugins", "list", "-o", "json"}) | ||
firstName := gjson.Get(jsonOut, "0.name").String() | ||
numPluginsInstalled := gjson.Get(jsonOut, "#").Int() | ||
Expect(int64(1)).To(Equal(numPluginsInstalled)) | ||
Expect(agentCfg.Spec.Plugin.Name).To(Equal(firstName)) | ||
|
||
Log("delete a agent config") | ||
Expect(k8sClient.Delete(ctx, agentCfg)).Should(Succeed()) | ||
Expect(waitForResourceDeleted(ctx, agentCfg)).Should(Succeed()) | ||
|
||
Log("verify persistent volums and claims no longer has the agent config in their owner reference") | ||
results := &corev1.PersistentVolumeClaimList{} | ||
Expect(k8sClient.List(ctx, results, client.InNamespace(agentCfg.Namespace), client.MatchingLabels(agentCfg.Spec.GetPluginsLabels()))).Should(Succeed()) | ||
for _, pvc := range results.Items { | ||
for _, ow := range pvc.OwnerReferences { | ||
if ow.Kind == "AgentConfig" { | ||
|
||
Expect(ow.Name).ShouldNot(Equal(agentCfg.Name)) | ||
} | ||
} | ||
key := client.ObjectKey{Namespace: agentCfg.Namespace, Name: pvc.Spec.VolumeName} | ||
pv := &corev1.PersistentVolume{} | ||
Expect(k8sClient.Get(ctx, key, pv)).Should(Succeed()) | ||
for _, ow := range pv.OwnerReferences { | ||
if ow.Kind == "AgentConfig" { | ||
|
||
Expect(ow.Name).ShouldNot(Equal(agentCfg.Name)) | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
// NewTestCredSet minimal CredentialSet CRD for tests | ||
func NewTestAgentCfg() *porterv1.AgentConfig { | ||
cs := &porterv1.AgentConfig{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "porter.sh/v1", | ||
Kind: "AgentConfig", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "porter-test-me-", | ||
}, | ||
Spec: porterv1.AgentConfigSpec{ | ||
Plugin: porterv1.Plugin{ | ||
Name: "kubernetes", | ||
}, | ||
}, | ||
} | ||
return cs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters