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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃尡 Use server side apply to update test resource #791

Merged
Merged
Changes from all commits
Commits
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
33 changes: 28 additions & 5 deletions test/e2e/cluster_extension_admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
)

func TestClusterExtensionPackageUniqueness(t *testing.T) {
ctx := context.Background()
fieldOwner := client.FieldOwner("operator-controller-e2e")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using SSA is valid and maybe we should have a wider discussion about how best to use it in e2e tests. But, we shouldn't be seeing conflicts of the type in the issue coming out of our test code. If we do it's because we forgot to get the latest from the server after a create or update. SSA is nice because it makes things feel more natural for e2e tests. Do we need to respect any conventions when using SSA? Should we switch all mutating interactions in e2e over to SSA?


deleteClusterExtension := func(clusterExtension *ocv1alpha1.ClusterExtension) {
require.NoError(t, c.Delete(ctx, clusterExtension))
Expand Down Expand Up @@ -64,12 +66,33 @@ func TestClusterExtensionPackageUniqueness(t *testing.T) {
defer deleteClusterExtension(clusterExtension2)

t.Log("update second resource with package which already exists on the cluster")
clusterExtension2.Spec.PackageName = firstResourcePackageName
perdasilva marked this conversation as resolved.
Show resolved Hide resolved
err = c.Update(ctx, clusterExtension2)
intent := &ocv1alpha1.ClusterExtension{
TypeMeta: metav1.TypeMeta{
APIVersion: ocv1alpha1.GroupVersion.String(),
Kind: "ClusterExtension",
},
ObjectMeta: metav1.ObjectMeta{
Name: clusterExtension2.Name,
perdasilva marked this conversation as resolved.
Show resolved Hide resolved
},
Spec: ocv1alpha1.ClusterExtensionSpec{
PackageName: firstResourcePackageName,
},
}
err = c.Patch(ctx, intent, client.Apply, client.ForceOwnership, fieldOwner)
require.ErrorContains(t, err, fmt.Sprintf("Package %q is already installed via ClusterExtension %q", firstResourcePackageName, firstResourceName))

t.Log("update second resource with package which does not exist on the cluster")
require.NoError(t, c.Get(ctx, types.NamespacedName{Name: clusterExtension2.Name}, clusterExtension2))
clusterExtension2.Spec.PackageName = "package3"
require.NoError(t, c.Update(ctx, clusterExtension2))
intent = &ocv1alpha1.ClusterExtension{
TypeMeta: metav1.TypeMeta{
APIVersion: ocv1alpha1.GroupVersion.String(),
Kind: "ClusterExtension",
},
ObjectMeta: metav1.ObjectMeta{
Name: clusterExtension2.Name,
},
Spec: ocv1alpha1.ClusterExtensionSpec{
PackageName: "package3",
},
}
require.NoError(t, c.Patch(ctx, intent, client.Apply, client.ForceOwnership, fieldOwner))
}
Loading