Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2141b6a
Initial Commit
aagusuab Aug 25, 2022
6b36414
edits from the comments
aagusuab Aug 30, 2022
ec33ada
Pushing changes based on comments
aagusuab Aug 31, 2022
8ec22a6
lint fix
aagusuab Aug 31, 2022
0cd18fa
Removing one of the namespaces for duplicate namespace error
aagusuab Aug 31, 2022
5e0c348
lint fixes
aagusuab Sep 1, 2022
9380dcc
debug + fixed the error
aagusuab Sep 1, 2022
714fa65
debug + fixed the error
aagusuab Sep 1, 2022
e8032d2
lint fix
aagusuab Sep 1, 2022
361a143
debugging
aagusuab Sep 1, 2022
88607f9
more formatting
aagusuab Sep 2, 2022
1978699
more formatting
aagusuab Sep 2, 2022
85ec2b5
fixes based on comments
aagusuab Sep 2, 2022
f29b8e5
fixes based on comments
aagusuab Sep 2, 2022
952ea65
fixes based on comments / Before adding more.
aagusuab Sep 2, 2022
2b1ad7b
addressed all the comments.
aagusuab Sep 6, 2022
68f0641
lint checks
aagusuab Sep 7, 2022
adab939
fixes from comments
aagusuab Sep 7, 2022
1f9e6db
Added comment for expectation
aagusuab Sep 7, 2022
e66112b
using .string() for namesapceType for easier readability, and removed…
aagusuab Sep 7, 2022
3a85194
removing a period
aagusuab Sep 7, 2022
56b2590
added more validation
aagusuab Sep 8, 2022
d16123b
fixed the validation
aagusuab Sep 8, 2022
69a0441
fix comment + import
aagusuab Sep 8, 2022
05216b2
add error handling
aagusuab Sep 8, 2022
403d2f8
import lint fix
aagusuab Sep 8, 2022
4bcb9f3
removing some things that weren't there
aagusuab Sep 9, 2022
cd29a19
Added comment for GenerateSpecHash
aagusuab Sep 9, 2022
ed8d58d
edited comment for generateSpecHash
aagusuab Sep 9, 2022
019d8a0
fixed based on comments.
aagusuab Sep 12, 2022
c018ce4
ensuring the MemberCluster CR is deleted.
aagusuab Sep 12, 2022
4a88163
lint fix
aagusuab Sep 12, 2022
b76a09a
go update to fix vulnerability
aagusuab Sep 13, 2022
4c7f8ea
trying changing just the trivy
aagusuab Sep 13, 2022
c23c8de
undoing trivy +updating specific module
aagusuab Sep 13, 2022
ab70608
updating go.mod
aagusuab Sep 13, 2022
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ require (
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 h1:D0B/7al0LLrVC8aWF4+oxpv/m8bc7ViFfVS8/gXGdqI=
golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -713,8 +713,8 @@ golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
34 changes: 30 additions & 4 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ Licensed under the MIT license.
package e2e

import (
"embed"
"fmt"
"os"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
workv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"

"go.goms.io/fleet/apis/v1alpha1"
"go.goms.io/fleet/pkg/utils"
"go.goms.io/fleet/test/e2e/framework"
testutils "go.goms.io/fleet/test/e2e/utils"
)

var (
Expand All @@ -27,14 +32,26 @@ var (
MemberCluster = framework.NewCluster(memberClusterName, scheme)
hubURL string
scheme = runtime.NewScheme()
genericCodecs = serializer.NewCodecFactory(scheme)
genericCodec = genericCodecs.UniversalDeserializer()

// This namespace will store Member cluster-related CRs, such as v1alpha1.MemberCluster
memberNamespace = testutils.NewNamespace(fmt.Sprintf(utils.NamespaceNameFormat, MemberCluster.ClusterName))

// This namespace in HubCluster will store v1alpha1.Work to simulate Work-related features in Hub Cluster.
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably belongs to the work api E2E test.

Copy link
Member Author

Choose a reason for hiding this comment

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

What we discussed was that we can move the namespace creation to work-api-e2e test since this namespace only belongs to the work-api testing.
However, when we are creating Hub and Member for testing, the works will be created in a specific namespace defined by the work-api on the hubCluster (Hence the workNamespace).
Therefore, we cannot create multiple namespaces for works, and we will be using one single namespace for the entire work-api test.
The WorkResource namespace however, I will move it to the work-api-e2e-test.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it is possible to separate out the work-api e2e setup from the fleet e2e (which includes hub/member cluster join/leave and placement) setup. In this way, we can create any number of namespaces for works

workNamespace = testutils.NewNamespace(fmt.Sprintf(utils.NamespaceNameFormat, MemberCluster.ClusterName))

// Used to decode an unstructured object.
genericCodecs = serializer.NewCodecFactory(scheme)
genericCodec = genericCodecs.UniversalDeserializer()

//go:embed manifests
TestManifestFiles embed.FS
)

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(workv1alpha1.AddToScheme(scheme))
utilruntime.Must(apiextensionsv1.AddToScheme(scheme))
}

func TestE2E(t *testing.T) {
Expand All @@ -44,10 +61,10 @@ func TestE2E(t *testing.T) {

var _ = BeforeSuite(func() {
kubeconfig := os.Getenv("KUBECONFIG")
Expect(kubeconfig).ShouldNot(BeEmpty())
Expect(kubeconfig).ShouldNot(BeEmpty(), "Failure to retrieve kubeconfig")

hubURL = os.Getenv("HUB_SERVER_URL")
Expect(hubURL).ShouldNot(BeEmpty())
Expect(hubURL).ShouldNot(BeEmpty(), "Failure to retrieve Hub URL")

// hub setup
HubCluster.HubURL = hubURL
Expand All @@ -57,4 +74,13 @@ var _ = BeforeSuite(func() {
MemberCluster.HubURL = hubURL
framework.GetClusterClient(MemberCluster)

testutils.CreateNamespace(*MemberCluster, memberNamespace)

testutils.CreateNamespace(*HubCluster, workNamespace)
})

var _ = AfterSuite(func() {
testutils.DeleteNamespace(*MemberCluster, memberNamespace)

testutils.DeleteNamespace(*HubCluster, workNamespace)
})
30 changes: 18 additions & 12 deletions test/e2e/framework/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"

"github.com/onsi/gomega"
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"
Expand All @@ -21,14 +22,16 @@ var (
kubeconfigPath = os.Getenv("KUBECONFIG")
)

// Cluster object defines the required clients based on the kubeconfig of the test cluster.
type Cluster struct {
Scheme *runtime.Scheme
KubeClient client.Client
KubeClientSet kubernetes.Interface
DynamicClient dynamic.Interface
ClusterName string
HubURL string
RestMapper meta.RESTMapper
Scheme *runtime.Scheme
KubeClient client.Client
KubeClientSet kubernetes.Interface
APIExtensionClient *clientset.Clientset
DynamicClient dynamic.Interface
ClusterName string
HubURL string
RestMapper meta.RESTMapper
}

func NewCluster(name string, scheme *runtime.Scheme) *Cluster {
Expand All @@ -44,20 +47,23 @@ func GetClusterClient(cluster *Cluster) {

restConfig, err := clusterConfig.ClientConfig()
if err != nil {
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(err).Should(gomega.Succeed(), "Failed to set up rest config")
}

cluster.KubeClient, err = client.New(restConfig, client.Options{Scheme: cluster.Scheme})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(err).Should(gomega.Succeed(), "Failed to set up Kube Client")

cluster.KubeClientSet, err = kubernetes.NewForConfig(restConfig)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(err).Should(gomega.Succeed(), "Failed to set up KubeClient Set")

cluster.APIExtensionClient, err = clientset.NewForConfig(restConfig)
gomega.Expect(err).Should(gomega.Succeed(), "Failed to set up API Extension Client")

cluster.DynamicClient, err = dynamic.NewForConfig(restConfig)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(err).Should(gomega.Succeed(), "Failed to set up Dynamic Client")

cluster.RestMapper, err = apiutil.NewDynamicRESTMapper(restConfig, apiutil.WithLazyDiscovery)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(err).Should(gomega.Succeed(), "Failed to set up Rest Mapper")
}

func GetClientConfig(cluster *Cluster) clientcmd.ClientConfig {
Expand Down
35 changes: 10 additions & 25 deletions test/e2e/join_leave_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,42 @@ package e2e

import (
"context"
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"go.goms.io/fleet/apis/v1alpha1"
"go.goms.io/fleet/pkg/utils"
testutils "go.goms.io/fleet/test/e2e/utils"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var _ = Describe("Join/leave member cluster testing", func() {
var mc *v1alpha1.MemberCluster
var sa *corev1.ServiceAccount
var memberNS *corev1.Namespace
var imc *v1alpha1.InternalMemberCluster
var ctx context.Context

BeforeEach(func() {
memberNS = testutils.NewNamespace(fmt.Sprintf(utils.NamespaceNameFormat, MemberCluster.ClusterName))
By("prepare resources in member cluster")
// create testing NS in member cluster
testutils.CreateNamespace(*MemberCluster, memberNS)
sa = testutils.NewServiceAccount(MemberCluster.ClusterName, memberNS.Name)
ctx = context.Background()

sa = testutils.NewServiceAccount(MemberCluster.ClusterName, memberNamespace.Name)
testutils.CreateServiceAccount(*MemberCluster, sa)

By("deploy member cluster in the hub cluster")
mc = testutils.NewMemberCluster(MemberCluster.ClusterName, 60, v1alpha1.ClusterStateJoin)
testutils.CreateMemberCluster(*HubCluster, mc)

By("check if internal member cluster created in the hub cluster")
imc = testutils.NewInternalMemberCluster(MemberCluster.ClusterName, memberNS.Name)
imc = testutils.NewInternalMemberCluster(MemberCluster.ClusterName, memberNamespace.Name)
testutils.WaitInternalMemberCluster(*HubCluster, imc)

By("check if member cluster is marked as readyToJoin")
testutils.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterReadyToJoin, v1.ConditionTrue, 3*testutils.PollTimeout)
})

AfterEach(func() {
testutils.DeleteNamespace(*MemberCluster, memberNS)
Eventually(func() bool {
err := MemberCluster.KubeClient.Get(context.TODO(), types.NamespacedName{Name: memberNS.Name, Namespace: ""}, memberNS)
return apierrors.IsNotFound(err)
}, testutils.PollTimeout, testutils.PollInterval).Should(Equal(true))
testutils.DeleteMemberCluster(*HubCluster, mc)
Eventually(func() bool {
err := HubCluster.KubeClient.Get(context.TODO(), types.NamespacedName{Name: memberNS.Name, Namespace: ""}, memberNS)
return apierrors.IsNotFound(err)
}, testutils.PollTimeout, testutils.PollInterval).Should(Equal(true))
testutils.DeleteMemberCluster(ctx, *HubCluster, mc)
testutils.DeleteServiceAccount(*MemberCluster, sa)

})

It("Join & Leave flow is successful ", func() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: test-configmap
name: test-configmap2
namespace: test-namespace
data:
fielda: one
9 changes: 9 additions & 0 deletions test/e2e/manifests/test-configmap2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: test-configmap2
namespace: default
data:
fielda: one
fieldb: two
fieldc: three
2 changes: 1 addition & 1 deletion test/e2e/manifests/test-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ metadata:
name: test-secret
namespace: default
data:
somekey: Q2xpZW50SWQ6IDUxOTEwNTY4LTM0YzktNGQ0ZS1iODA1LTNmNTY3NWQyMDdiYwpDbGllbnRTZWNyZXQ6IDZSLThRfkJvSDNNYm1+eGJpaDhmNVZibHBkWGxzeGQyRnp+WXhjWjYKVGVuYW50SWQ6IDcyZjk4OGJmLTg2ZjEtNDFhZi05MWFiLTJkN2NkMDExZGI0NwpTdWJzY3JpcHRpb25JZDogMmIwM2JmYjgtZTg4NS00NTY2LWE2MmEtOTA5YTExZDcxNjkyClJlc291cmNlR3JvdXA6IGNhcmF2ZWwtZGVtbw==
somekey: dGVzdA==
type: generic
2 changes: 1 addition & 1 deletion test/e2e/manifests/test-serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: test-serviceaccount
namespace: default
namespace: default
Loading