From 9aef4ded293a023690b14ccc245898b8d45ec92a Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 7 Feb 2023 14:39:47 -0300 Subject: [PATCH 01/17] fix: failing service util test --- pkg/util/k8sutil/service_utils_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/util/k8sutil/service_utils_test.go b/pkg/util/k8sutil/service_utils_test.go index 426549152..3b452bdee 100644 --- a/pkg/util/k8sutil/service_utils_test.go +++ b/pkg/util/k8sutil/service_utils_test.go @@ -165,7 +165,7 @@ func TestApplyServicePolicyWithClusterIP(t *testing.T) { } applyServicePolicy(svc, policy) actualType := svc.Spec.Type - actualClusterIP := svc.Spec.Type + actualClusterIP := svc.Spec.ClusterIP if !reflect.DeepEqual(serviceType, actualType) { t.Errorf("expect expected=%v, got=%v", serviceType, actualType) } From a880b6e606ca0f4a8d98a5376a01596fc788b9b3 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 14 Feb 2023 18:45:25 -0300 Subject: [PATCH 02/17] chore: set different command if distributed clustering mode --- pkg/apis/etcd/v1beta2/cluster.go | 3 + pkg/util/k8sutil/k8sutil.go | 52 ++++++++++--- pkg/util/k8sutil/k8sutils_test.go | 118 ++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+), 12 deletions(-) diff --git a/pkg/apis/etcd/v1beta2/cluster.go b/pkg/apis/etcd/v1beta2/cluster.go index 10125a700..24be6cd1a 100644 --- a/pkg/apis/etcd/v1beta2/cluster.go +++ b/pkg/apis/etcd/v1beta2/cluster.go @@ -102,6 +102,9 @@ type ClusterSpec struct { // etcd cluster TLS configuration TLS *TLSPolicy `json:"TLS,omitempty"` + + ClusteringMode string `json:"clusteringMode,omitempty"` + ClusterToken string `json:"clusterToken,omitempty"` } // PodPolicy defines the policy to create pod for the etcd container. diff --git a/pkg/util/k8sutil/k8sutil.go b/pkg/util/k8sutil/k8sutil.go index 5ca1f0a39..4c7274a6c 100644 --- a/pkg/util/k8sutil/k8sutil.go +++ b/pkg/util/k8sutil/k8sutil.go @@ -72,6 +72,10 @@ const ( // defaultDNSTimeout is the default maximum allowed time for the init container of the etcd pod // to reverse DNS lookup its IP. The default behavior is to wait forever and has a value of 0. defaultDNSTimeout = int64(0) + + // discoveryEndpoint is the endpoint to be used for discovery service. The default is the public etcd + // service endpoint + discoveryEndpoint = "https://discovery.etcd.io" ) func GetEtcdVersion(pod *v1.Pod) string { @@ -306,10 +310,18 @@ func addOwnerRefToObject(o metav1.Object, r metav1.OwnerReference) { o.SetOwnerReferences(append(o.GetOwnerReferences(), r)) } +func createToken(clusterSpec api.ClusterSpec) string { + if clusterSpec.ClusteringMode == "distributed" { + return clusterSpec.ClusterToken + } else { + return uuid.New() + } +} + // NewSeedMemberPod returns a Pod manifest for a seed member. // It's special that it has new token, and might need recovery init containers func NewSeedMemberPod(ctx context.Context, kubecli kubernetes.Interface, clusterName, clusterNamespace string, ms etcdutil.MemberSet, m *etcdutil.Member, cs api.ClusterSpec, owner metav1.OwnerReference, backupURL *url.URL) (*v1.Pod, error) { - token := uuid.New() + token := createToken(cs) pod, err := newEtcdPod(ctx, kubecli, m, ms.PeerURLPairs(), clusterName, clusterNamespace, "new", token, cs) // TODO: PVC datadir support for restore process AddEtcdVolumeToPod(pod, nil, cs.Pod.Tmpfs) @@ -339,20 +351,39 @@ func ClientServiceName(clusterName string) string { return clusterName + "-client" } -func newEtcdPod(ctx context.Context, kubecli kubernetes.Interface, m *etcdutil.Member, initialCluster []string, clusterName, clusterNamespace, state, token string, cs api.ClusterSpec) (*v1.Pod, error) { - commands := fmt.Sprintf("/usr/local/bin/etcd --data-dir=%s --name=%s --initial-advertise-peer-urls=%s "+ +func setupInitialEtcdCommand(dataDir string, m *etcdutil.Member, initialCluster string, clusterState string, clusterToken string, clusteringMode string) (string, error) { + if clusteringMode == "distributed" { + command := fmt.Sprintf("/usr/local/bin/etcd --data-dir=%s --name=%s --initial-advertise-peer-urls=%s "+ + "--listen-peer-urls=%s --listen-client-urls=%s --advertise-client-urls=%s "+ + "--discovery=%s/%s", + dataDir, m.Name, m.PeerURL(), m.ListenPeerURL(), m.ListenClientURL(), m.ClientURL(), discoveryEndpoint, clusterToken) + return command, nil + } else { + command := fmt.Sprintf("/usr/local/bin/etcd --data-dir=%s --name=%s --initial-advertise-peer-urls=%s "+ "--listen-peer-urls=%s --listen-client-urls=%s --advertise-client-urls=%s "+ "--initial-cluster=%s --initial-cluster-state=%s", - dataDir, m.Name, m.PeerURL(), m.ListenPeerURL(), m.ListenClientURL(), m.ClientURL(), strings.Join(initialCluster, ","), state) + dataDir, m.Name, m.PeerURL(), m.ListenPeerURL(), m.ListenClientURL(), m.ClientURL(), initialCluster, clusterState) + if clusterState == "new" { + command = fmt.Sprintf("%s --initial-cluster-token=%s", command, clusterToken) + } + return command, nil + } +} + +func newEtcdPod(ctx context.Context, kubecli kubernetes.Interface, m *etcdutil.Member, initialCluster []string, clusterName, clusterNamespace, state, token string, cs api.ClusterSpec) (*v1.Pod, error) { + command, err := setupInitialEtcdCommand(dataDir, m, strings.Join(initialCluster, ","), state, token, cs.ClusteringMode) + if err != nil { + return nil, err + } if m.SecurePeer { secret, err := kubecli.CoreV1().Secrets(clusterNamespace).Get(ctx, cs.TLS.Static.Member.PeerSecret, metav1.GetOptions{}) if err != nil { return nil, err } if secret.Type == v1.SecretTypeTLS { - commands += fmt.Sprintf(" --peer-client-cert-auth=true --peer-trusted-ca-file=%[1]s/ca.crt --peer-cert-file=%[1]s/tls.crt --peer-key-file=%[1]s/tls.key", peerTLSDir) + command += fmt.Sprintf(" --peer-client-cert-auth=true --peer-trusted-ca-file=%[1]s/ca.crt --peer-cert-file=%[1]s/tls.crt --peer-key-file=%[1]s/tls.key", peerTLSDir) } else { - commands += fmt.Sprintf(" --peer-client-cert-auth=true --peer-trusted-ca-file=%[1]s/peer-ca.crt --peer-cert-file=%[1]s/peer.crt --peer-key-file=%[1]s/peer.key", peerTLSDir) + command += fmt.Sprintf(" --peer-client-cert-auth=true --peer-trusted-ca-file=%[1]s/peer-ca.crt --peer-cert-file=%[1]s/peer.crt --peer-key-file=%[1]s/peer.key", peerTLSDir) } } if m.SecureClient { @@ -361,14 +392,11 @@ func newEtcdPod(ctx context.Context, kubecli kubernetes.Interface, m *etcdutil.M return nil, err } if secret.Type == v1.SecretTypeTLS { - commands += fmt.Sprintf(" --client-cert-auth=true --trusted-ca-file=%[1]s/ca.crt --cert-file=%[1]s/tls.crt --key-file=%[1]s/tls.key", serverTLSDir) + command += fmt.Sprintf(" --client-cert-auth=true --trusted-ca-file=%[1]s/ca.crt --cert-file=%[1]s/tls.crt --key-file=%[1]s/tls.key", serverTLSDir) } else { - commands += fmt.Sprintf(" --client-cert-auth=true --trusted-ca-file=%[1]s/server-ca.crt --cert-file=%[1]s/server.crt --key-file=%[1]s/server.key", serverTLSDir) + command += fmt.Sprintf(" --client-cert-auth=true --trusted-ca-file=%[1]s/server-ca.crt --cert-file=%[1]s/server.crt --key-file=%[1]s/server.key", serverTLSDir) } } - if state == "new" { - commands = fmt.Sprintf("%s --initial-cluster-token=%s", commands, token) - } labels := map[string]string{ "app": "etcd", @@ -393,7 +421,7 @@ func newEtcdPod(ctx context.Context, kubecli kubernetes.Interface, m *etcdutil.M readinessProbe.FailureThreshold = 3 container := containerWithProbes( - etcdContainer(strings.Split(commands, " "), cs.Repository, cs.Version), + etcdContainer(strings.Split(command, " "), cs.Repository, cs.Version), livenessProbe, readinessProbe) diff --git a/pkg/util/k8sutil/k8sutils_test.go b/pkg/util/k8sutil/k8sutils_test.go index cce491401..eb39d9cfa 100644 --- a/pkg/util/k8sutil/k8sutils_test.go +++ b/pkg/util/k8sutil/k8sutils_test.go @@ -16,8 +16,10 @@ package k8sutil import ( "testing" + "strings" api "github.com/coreos/etcd-operator/pkg/apis/etcd/v1beta2" + "github.com/coreos/etcd-operator/pkg/util/etcdutil" ) func TestDefaultBusyboxImageName(t *testing.T) { @@ -47,3 +49,119 @@ func TestSetBusyboxImageName(t *testing.T) { t.Errorf("expect image=%s, get=%s", expected, image) } } + +func TestEtcdCommandNewLocalCluster(t *testing.T) { + dataDir := "/var/etcd/data" + etcdMember := &etcdutil.Member{ + Name: "etcd-test", + Namespace: "etcd", + SecurePeer: false, + SecureClient: false, + ClusterDomain: ".local", + } + memberSet := etcdutil.NewMemberSet(etcdMember).PeerURLPairs() + clusterState := "new" + token := "token" + + initialEtcdCommand, _ := setupInitialEtcdCommand(dataDir, etcdMember, strings.Join(memberSet, ","), clusterState, token, "") + + expectedCommand := "/usr/local/bin/etcd --data-dir=/var/etcd/data --name=etcd-test --initial-advertise-peer-urls=http://etcd-test.etcd.etcd.svc.local:2380 "+ + "--listen-peer-urls=http://0.0.0.0:2380 --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://etcd-test.etcd.etcd.svc.local:2379 "+ + "--initial-cluster=etcd-test=http://etcd-test.etcd.etcd.svc.local:2380 --initial-cluster-state=new --initial-cluster-token=token" + + if initialEtcdCommand != expectedCommand { + t.Errorf("expected command=%s, got=%s", expectedCommand, initialEtcdCommand) + } +} + +//TODO +func TestEtcdCommandExistingLocalCluster(t *testing.T) { + dataDir := "/var/etcd/data" + etcdMember1 := &etcdutil.Member{ + Name: "etcd-test-1", + Namespace: "etcd", + SecurePeer: false, + SecureClient: false, + ClusterDomain: ".local", + } + etcdMember2 := &etcdutil.Member{ + Name: "etcd-test-2", + Namespace: "etcd", + SecurePeer: false, + SecureClient: false, + ClusterDomain: ".local", + } + memberSet := etcdutil.NewMemberSet(etcdMember1) + memberSet.Add(etcdMember2) + memberSetURLs := memberSet.PeerURLPairs() + token := "token" + clusterState := "existing" + + initialEtcdCommand, _ := setupInitialEtcdCommand(dataDir, etcdMember2, strings.Join(memberSetURLs, ","), clusterState, token, "") + + expectedCommand := "/usr/local/bin/etcd --data-dir=/var/etcd/data --name=etcd-test-2 --initial-advertise-peer-urls=http://etcd-test-2.etcd-test.etcd.svc.local:2380 "+ + "--listen-peer-urls=http://0.0.0.0:2380 --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://etcd-test-2.etcd-test.etcd.svc.local:2379 "+ + "--initial-cluster=etcd-test-1=http://etcd-test-1.etcd-test.etcd.svc.local:2380,etcd-test-2=http://etcd-test-2.etcd-test.etcd.svc.local:2380 --initial-cluster-state=existing" + + if initialEtcdCommand != expectedCommand { + t.Errorf("expected command=%s, got=%s", expectedCommand, initialEtcdCommand) + } +} + +//ToDo +func TestEtcdCommandInvalidClusterMode(t *testing.T) { + +} + +func TestEtcdCommandDistributedCluster(t *testing.T) { + dataDir := "/var/etcd/data" + etcdMember := &etcdutil.Member{ + Name: "etcd-test", + Namespace: "etcd", + SecurePeer: false, + SecureClient: false, + ClusterDomain: ".local", + } + memberSet := etcdutil.NewMemberSet(etcdMember).PeerURLPairs() + clusterState := "new" + clusterToken := "token" + clusteringMode := "distributed" + + initialEtcdCommand, _ := setupInitialEtcdCommand(dataDir, etcdMember, strings.Join(memberSet, ","), clusterState, clusterToken, clusteringMode) + + expectedCommand := "/usr/local/bin/etcd --data-dir=/var/etcd/data --name=etcd-test --initial-advertise-peer-urls=http://etcd-test.etcd.etcd.svc.local:2380 "+ + "--listen-peer-urls=http://0.0.0.0:2380 --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://etcd-test.etcd.etcd.svc.local:2379 "+ + "--discovery=https://discovery.etcd.io/token" + + if initialEtcdCommand != expectedCommand { + t.Errorf("expected command=%s, got=%s", expectedCommand, initialEtcdCommand) + } +} + +func TestCreateTokenLocalCluster(t *testing.T) { + clusterSpec := &api.ClusterSpec{ + Size: 1, + ClusteringMode: "local", + ClusterToken: "testtoken", + } + + token := createToken(*clusterSpec) + + if token == "testtoken" { + t.Errorf("token should be a randon uuid, instead got %s", token) + } +} + +func TestCreateTokenDistributedCluster(t *testing.T) { + clusterSpec := &api.ClusterSpec{ + Size: 1, + ClusteringMode: "distributed", + ClusterToken: "testtoken", + } + + token := createToken(*clusterSpec) + + if token != "testtoken" { + t.Errorf("expected token=%s, got=%s", clusterSpec.ClusterToken, token) + } +} \ No newline at end of file From ebd629ee60807d7fedabb669995058d77f8f7a65 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 15 Feb 2023 19:20:20 -0300 Subject: [PATCH 03/17] chore: test for invalid clustering mode --- pkg/util/k8sutil/k8sutil.go | 18 +++--- pkg/util/k8sutil/k8sutils_test.go | 93 +++++++++++++++++++------------ 2 files changed, 66 insertions(+), 45 deletions(-) diff --git a/pkg/util/k8sutil/k8sutil.go b/pkg/util/k8sutil/k8sutil.go index 4c7274a6c..a1bb2d78e 100644 --- a/pkg/util/k8sutil/k8sutil.go +++ b/pkg/util/k8sutil/k8sutil.go @@ -73,7 +73,7 @@ const ( // to reverse DNS lookup its IP. The default behavior is to wait forever and has a value of 0. defaultDNSTimeout = int64(0) - // discoveryEndpoint is the endpoint to be used for discovery service. The default is the public etcd + // discoveryEndpoint is the endpoint to be used for discovery service. The default is the public etcd // service endpoint discoveryEndpoint = "https://discovery.etcd.io" ) @@ -351,18 +351,18 @@ func ClientServiceName(clusterName string) string { return clusterName + "-client" } -func setupInitialEtcdCommand(dataDir string, m *etcdutil.Member, initialCluster string, clusterState string, clusterToken string, clusteringMode string) (string, error) { +func setupEtcdCommand(dataDir string, m *etcdutil.Member, initialCluster string, clusterState string, clusterToken string, clusteringMode string) (string, error) { if clusteringMode == "distributed" { command := fmt.Sprintf("/usr/local/bin/etcd --data-dir=%s --name=%s --initial-advertise-peer-urls=%s "+ - "--listen-peer-urls=%s --listen-client-urls=%s --advertise-client-urls=%s "+ - "--discovery=%s/%s", - dataDir, m.Name, m.PeerURL(), m.ListenPeerURL(), m.ListenClientURL(), m.ClientURL(), discoveryEndpoint, clusterToken) + "--listen-peer-urls=%s --listen-client-urls=%s --advertise-client-urls=%s "+ + "--discovery=%s/%s", + dataDir, m.Name, m.PeerURL(), m.ListenPeerURL(), m.ListenClientURL(), m.ClientURL(), discoveryEndpoint, clusterToken) return command, nil } else { command := fmt.Sprintf("/usr/local/bin/etcd --data-dir=%s --name=%s --initial-advertise-peer-urls=%s "+ - "--listen-peer-urls=%s --listen-client-urls=%s --advertise-client-urls=%s "+ - "--initial-cluster=%s --initial-cluster-state=%s", - dataDir, m.Name, m.PeerURL(), m.ListenPeerURL(), m.ListenClientURL(), m.ClientURL(), initialCluster, clusterState) + "--listen-peer-urls=%s --listen-client-urls=%s --advertise-client-urls=%s "+ + "--initial-cluster=%s --initial-cluster-state=%s", + dataDir, m.Name, m.PeerURL(), m.ListenPeerURL(), m.ListenClientURL(), m.ClientURL(), initialCluster, clusterState) if clusterState == "new" { command = fmt.Sprintf("%s --initial-cluster-token=%s", command, clusterToken) } @@ -371,7 +371,7 @@ func setupInitialEtcdCommand(dataDir string, m *etcdutil.Member, initialCluster } func newEtcdPod(ctx context.Context, kubecli kubernetes.Interface, m *etcdutil.Member, initialCluster []string, clusterName, clusterNamespace, state, token string, cs api.ClusterSpec) (*v1.Pod, error) { - command, err := setupInitialEtcdCommand(dataDir, m, strings.Join(initialCluster, ","), state, token, cs.ClusteringMode) + command, err := setupEtcdCommand(dataDir, m, strings.Join(initialCluster, ","), state, token, cs.ClusteringMode) if err != nil { return nil, err } diff --git a/pkg/util/k8sutil/k8sutils_test.go b/pkg/util/k8sutil/k8sutils_test.go index eb39d9cfa..c7bddd19f 100644 --- a/pkg/util/k8sutil/k8sutils_test.go +++ b/pkg/util/k8sutil/k8sutils_test.go @@ -15,8 +15,8 @@ package k8sutil import ( - "testing" "strings" + "testing" api "github.com/coreos/etcd-operator/pkg/apis/etcd/v1beta2" "github.com/coreos/etcd-operator/pkg/util/etcdutil" @@ -53,21 +53,21 @@ func TestSetBusyboxImageName(t *testing.T) { func TestEtcdCommandNewLocalCluster(t *testing.T) { dataDir := "/var/etcd/data" etcdMember := &etcdutil.Member{ - Name: "etcd-test", - Namespace: "etcd", - SecurePeer: false, - SecureClient: false, + Name: "etcd-test", + Namespace: "etcd", + SecurePeer: false, + SecureClient: false, ClusterDomain: ".local", } memberSet := etcdutil.NewMemberSet(etcdMember).PeerURLPairs() clusterState := "new" token := "token" - - initialEtcdCommand, _ := setupInitialEtcdCommand(dataDir, etcdMember, strings.Join(memberSet, ","), clusterState, token, "") - expectedCommand := "/usr/local/bin/etcd --data-dir=/var/etcd/data --name=etcd-test --initial-advertise-peer-urls=http://etcd-test.etcd.etcd.svc.local:2380 "+ - "--listen-peer-urls=http://0.0.0.0:2380 --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://etcd-test.etcd.etcd.svc.local:2379 "+ - "--initial-cluster=etcd-test=http://etcd-test.etcd.etcd.svc.local:2380 --initial-cluster-state=new --initial-cluster-token=token" + initialEtcdCommand, _ := setupEtcdCommand(dataDir, etcdMember, strings.Join(memberSet, ","), clusterState, token, "") + + expectedCommand := "/usr/local/bin/etcd --data-dir=/var/etcd/data --name=etcd-test --initial-advertise-peer-urls=http://etcd-test.etcd.etcd.svc.local:2380 " + + "--listen-peer-urls=http://0.0.0.0:2380 --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://etcd-test.etcd.etcd.svc.local:2379 " + + "--initial-cluster=etcd-test=http://etcd-test.etcd.etcd.svc.local:2380 --initial-cluster-state=new --initial-cluster-token=token" if initialEtcdCommand != expectedCommand { t.Errorf("expected command=%s, got=%s", expectedCommand, initialEtcdCommand) @@ -78,17 +78,17 @@ func TestEtcdCommandNewLocalCluster(t *testing.T) { func TestEtcdCommandExistingLocalCluster(t *testing.T) { dataDir := "/var/etcd/data" etcdMember1 := &etcdutil.Member{ - Name: "etcd-test-1", - Namespace: "etcd", - SecurePeer: false, - SecureClient: false, + Name: "etcd-test-1", + Namespace: "etcd", + SecurePeer: false, + SecureClient: false, ClusterDomain: ".local", } etcdMember2 := &etcdutil.Member{ - Name: "etcd-test-2", - Namespace: "etcd", - SecurePeer: false, - SecureClient: false, + Name: "etcd-test-2", + Namespace: "etcd", + SecurePeer: false, + SecureClient: false, ClusterDomain: ".local", } memberSet := etcdutil.NewMemberSet(etcdMember1) @@ -96,12 +96,12 @@ func TestEtcdCommandExistingLocalCluster(t *testing.T) { memberSetURLs := memberSet.PeerURLPairs() token := "token" clusterState := "existing" - - initialEtcdCommand, _ := setupInitialEtcdCommand(dataDir, etcdMember2, strings.Join(memberSetURLs, ","), clusterState, token, "") - expectedCommand := "/usr/local/bin/etcd --data-dir=/var/etcd/data --name=etcd-test-2 --initial-advertise-peer-urls=http://etcd-test-2.etcd-test.etcd.svc.local:2380 "+ - "--listen-peer-urls=http://0.0.0.0:2380 --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://etcd-test-2.etcd-test.etcd.svc.local:2379 "+ - "--initial-cluster=etcd-test-1=http://etcd-test-1.etcd-test.etcd.svc.local:2380,etcd-test-2=http://etcd-test-2.etcd-test.etcd.svc.local:2380 --initial-cluster-state=existing" + initialEtcdCommand, _ := setupEtcdCommand(dataDir, etcdMember2, strings.Join(memberSetURLs, ","), clusterState, token, "") + + expectedCommand := "/usr/local/bin/etcd --data-dir=/var/etcd/data --name=etcd-test-2 --initial-advertise-peer-urls=http://etcd-test-2.etcd-test.etcd.svc.local:2380 " + + "--listen-peer-urls=http://0.0.0.0:2380 --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://etcd-test-2.etcd-test.etcd.svc.local:2379 " + + "--initial-cluster=etcd-test-1=http://etcd-test-1.etcd-test.etcd.svc.local:2380,etcd-test-2=http://etcd-test-2.etcd-test.etcd.svc.local:2380 --initial-cluster-state=existing" if initialEtcdCommand != expectedCommand { t.Errorf("expected command=%s, got=%s", expectedCommand, initialEtcdCommand) @@ -110,16 +110,37 @@ func TestEtcdCommandExistingLocalCluster(t *testing.T) { //ToDo func TestEtcdCommandInvalidClusterMode(t *testing.T) { + dataDir := "/var/etcd/data" + etcdMember := &etcdutil.Member{ + Name: "etcd-test", + Namespace: "etcd", + SecurePeer: false, + SecureClient: false, + ClusterDomain: ".local", + } + memberSet := etcdutil.NewMemberSet(etcdMember).PeerURLPairs() + clusterState := "new" + token := "token" + clusteringMode := "invalid" + + initialEtcdCommand, _ := setupEtcdCommand(dataDir, etcdMember, strings.Join(memberSet, ","), clusterState, token, clusteringMode) + + expectedCommand := "/usr/local/bin/etcd --data-dir=/var/etcd/data --name=etcd-test --initial-advertise-peer-urls=http://etcd-test.etcd.etcd.svc.local:2380 " + + "--listen-peer-urls=http://0.0.0.0:2380 --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://etcd-test.etcd.etcd.svc.local:2379 " + + "--initial-cluster=etcd-test=http://etcd-test.etcd.etcd.svc.local:2380 --initial-cluster-state=new --initial-cluster-token=token" + if initialEtcdCommand != expectedCommand { + t.Errorf("expected command=%s, got=%s", expectedCommand, initialEtcdCommand) + } } func TestEtcdCommandDistributedCluster(t *testing.T) { dataDir := "/var/etcd/data" etcdMember := &etcdutil.Member{ - Name: "etcd-test", - Namespace: "etcd", - SecurePeer: false, - SecureClient: false, + Name: "etcd-test", + Namespace: "etcd", + SecurePeer: false, + SecureClient: false, ClusterDomain: ".local", } memberSet := etcdutil.NewMemberSet(etcdMember).PeerURLPairs() @@ -127,11 +148,11 @@ func TestEtcdCommandDistributedCluster(t *testing.T) { clusterToken := "token" clusteringMode := "distributed" - initialEtcdCommand, _ := setupInitialEtcdCommand(dataDir, etcdMember, strings.Join(memberSet, ","), clusterState, clusterToken, clusteringMode) + initialEtcdCommand, _ := setupEtcdCommand(dataDir, etcdMember, strings.Join(memberSet, ","), clusterState, clusterToken, clusteringMode) - expectedCommand := "/usr/local/bin/etcd --data-dir=/var/etcd/data --name=etcd-test --initial-advertise-peer-urls=http://etcd-test.etcd.etcd.svc.local:2380 "+ - "--listen-peer-urls=http://0.0.0.0:2380 --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://etcd-test.etcd.etcd.svc.local:2379 "+ - "--discovery=https://discovery.etcd.io/token" + expectedCommand := "/usr/local/bin/etcd --data-dir=/var/etcd/data --name=etcd-test --initial-advertise-peer-urls=http://etcd-test.etcd.etcd.svc.local:2380 " + + "--listen-peer-urls=http://0.0.0.0:2380 --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://etcd-test.etcd.etcd.svc.local:2379 " + + "--discovery=https://discovery.etcd.io/token" if initialEtcdCommand != expectedCommand { t.Errorf("expected command=%s, got=%s", expectedCommand, initialEtcdCommand) @@ -140,9 +161,9 @@ func TestEtcdCommandDistributedCluster(t *testing.T) { func TestCreateTokenLocalCluster(t *testing.T) { clusterSpec := &api.ClusterSpec{ - Size: 1, + Size: 1, ClusteringMode: "local", - ClusterToken: "testtoken", + ClusterToken: "testtoken", } token := createToken(*clusterSpec) @@ -154,9 +175,9 @@ func TestCreateTokenLocalCluster(t *testing.T) { func TestCreateTokenDistributedCluster(t *testing.T) { clusterSpec := &api.ClusterSpec{ - Size: 1, + Size: 1, ClusteringMode: "distributed", - ClusterToken: "testtoken", + ClusterToken: "testtoken", } token := createToken(*clusterSpec) @@ -164,4 +185,4 @@ func TestCreateTokenDistributedCluster(t *testing.T) { if token != "testtoken" { t.Errorf("expected token=%s, got=%s", clusterSpec.ClusterToken, token) } -} \ No newline at end of file +} From e73f655e1ad4d5a99fcfb7438d6338aabb4a63ce Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 15 Feb 2023 19:48:47 -0300 Subject: [PATCH 04/17] chore: enable gh actions for pull requests --- .github/workflows/go-build.yml | 3 +-- .github/workflows/go-test-e2e.yml | 3 +-- .github/workflows/go-test.yml | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go-build.yml b/.github/workflows/go-build.yml index eaff023a8..b908cb618 100644 --- a/.github/workflows/go-build.yml +++ b/.github/workflows/go-build.yml @@ -1,6 +1,5 @@ name: Build -on: - push: +on: [push, pull_request] jobs: operator: name: Operator diff --git a/.github/workflows/go-test-e2e.yml b/.github/workflows/go-test-e2e.yml index 5e80165e5..e1d10bb40 100644 --- a/.github/workflows/go-test-e2e.yml +++ b/.github/workflows/go-test-e2e.yml @@ -1,6 +1,5 @@ name: Testing E2E -on: - push: +on: [push, pull_request] jobs: prepare: name: Prepare diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 909fbba9d..a5c6939a2 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -1,6 +1,5 @@ name: Testing -on: - push: +on: [push, pull_request] jobs: build: From e6a0f9a7bdcb788919fe07df7f31f68e923d2322 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 16 Feb 2023 13:49:45 -0300 Subject: [PATCH 05/17] chore: change cluster mode from distributed to discovery --- pkg/util/k8sutil/k8sutil.go | 4 ++-- pkg/util/k8sutil/k8sutils_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/util/k8sutil/k8sutil.go b/pkg/util/k8sutil/k8sutil.go index a1bb2d78e..9bd0b5629 100644 --- a/pkg/util/k8sutil/k8sutil.go +++ b/pkg/util/k8sutil/k8sutil.go @@ -311,7 +311,7 @@ func addOwnerRefToObject(o metav1.Object, r metav1.OwnerReference) { } func createToken(clusterSpec api.ClusterSpec) string { - if clusterSpec.ClusteringMode == "distributed" { + if clusterSpec.ClusteringMode == "discovery" { return clusterSpec.ClusterToken } else { return uuid.New() @@ -352,7 +352,7 @@ func ClientServiceName(clusterName string) string { } func setupEtcdCommand(dataDir string, m *etcdutil.Member, initialCluster string, clusterState string, clusterToken string, clusteringMode string) (string, error) { - if clusteringMode == "distributed" { + if clusteringMode == "discovery" { command := fmt.Sprintf("/usr/local/bin/etcd --data-dir=%s --name=%s --initial-advertise-peer-urls=%s "+ "--listen-peer-urls=%s --listen-client-urls=%s --advertise-client-urls=%s "+ "--discovery=%s/%s", diff --git a/pkg/util/k8sutil/k8sutils_test.go b/pkg/util/k8sutil/k8sutils_test.go index c7bddd19f..9a2cd17e6 100644 --- a/pkg/util/k8sutil/k8sutils_test.go +++ b/pkg/util/k8sutil/k8sutils_test.go @@ -146,7 +146,7 @@ func TestEtcdCommandDistributedCluster(t *testing.T) { memberSet := etcdutil.NewMemberSet(etcdMember).PeerURLPairs() clusterState := "new" clusterToken := "token" - clusteringMode := "distributed" + clusteringMode := "discovery" initialEtcdCommand, _ := setupEtcdCommand(dataDir, etcdMember, strings.Join(memberSet, ","), clusterState, clusterToken, clusteringMode) @@ -176,7 +176,7 @@ func TestCreateTokenLocalCluster(t *testing.T) { func TestCreateTokenDistributedCluster(t *testing.T) { clusterSpec := &api.ClusterSpec{ Size: 1, - ClusteringMode: "distributed", + ClusteringMode: "discovery", ClusterToken: "testtoken", } From 610578b8d62cf156c12d77149d7274d51b469d5d Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 16 Feb 2023 14:46:48 -0300 Subject: [PATCH 06/17] chore: validate if token is set when discovery cluster mode --- pkg/controller/restore-operator/sync.go | 3 +++ pkg/util/k8sutil/k8sutil.go | 18 +++++++++++--- pkg/util/k8sutil/k8sutils_test.go | 33 ++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/pkg/controller/restore-operator/sync.go b/pkg/controller/restore-operator/sync.go index d985bf825..b6eef9450 100644 --- a/pkg/controller/restore-operator/sync.go +++ b/pkg/controller/restore-operator/sync.go @@ -225,6 +225,9 @@ func (r *Restore) createSeedMember(ctx context.Context, ec *api.EtcdCluster, svc backupURL := backupapi.BackupURLForRestore("http", svcAddr, clusterName, namespace) ec.SetDefaults() pod, err := k8sutil.NewSeedMemberPod(ctx, r.kubecli, clusterName, namespace, ms, m, ec.Spec, owner, backupURL) + if err != nil { + return err + } _, err = r.kubecli.CoreV1().Pods(ec.Namespace).Create(ctx, pod, metav1.CreateOptions{}) return err } diff --git a/pkg/util/k8sutil/k8sutil.go b/pkg/util/k8sutil/k8sutil.go index 9bd0b5629..4459ca717 100644 --- a/pkg/util/k8sutil/k8sutil.go +++ b/pkg/util/k8sutil/k8sutil.go @@ -17,6 +17,7 @@ package k8sutil import ( "context" "encoding/json" + "errors" "fmt" "net" "net/url" @@ -78,6 +79,8 @@ const ( discoveryEndpoint = "https://discovery.etcd.io" ) +var ErrDiscoveryTokenNotProvided = errors.New("cluster token not provided, you must provide a token when clustering mode is discovery") + func GetEtcdVersion(pod *v1.Pod) string { return pod.Annotations[etcdVersionAnnotationKey] } @@ -310,18 +313,25 @@ func addOwnerRefToObject(o metav1.Object, r metav1.OwnerReference) { o.SetOwnerReferences(append(o.GetOwnerReferences(), r)) } -func createToken(clusterSpec api.ClusterSpec) string { +func createToken(clusterSpec api.ClusterSpec) (string, error) { if clusterSpec.ClusteringMode == "discovery" { - return clusterSpec.ClusterToken + if clusterSpec.ClusterToken == "" { + return "", ErrDiscoveryTokenNotProvided + } else { + return clusterSpec.ClusterToken, nil + } } else { - return uuid.New() + return uuid.New(), nil } } // NewSeedMemberPod returns a Pod manifest for a seed member. // It's special that it has new token, and might need recovery init containers func NewSeedMemberPod(ctx context.Context, kubecli kubernetes.Interface, clusterName, clusterNamespace string, ms etcdutil.MemberSet, m *etcdutil.Member, cs api.ClusterSpec, owner metav1.OwnerReference, backupURL *url.URL) (*v1.Pod, error) { - token := createToken(cs) + token, err := createToken(cs) + if err != nil { + return nil, err + } pod, err := newEtcdPod(ctx, kubecli, m, ms.PeerURLPairs(), clusterName, clusterNamespace, "new", token, cs) // TODO: PVC datadir support for restore process AddEtcdVolumeToPod(pod, nil, cs.Pod.Tmpfs) diff --git a/pkg/util/k8sutil/k8sutils_test.go b/pkg/util/k8sutil/k8sutils_test.go index 9a2cd17e6..484d3b59f 100644 --- a/pkg/util/k8sutil/k8sutils_test.go +++ b/pkg/util/k8sutil/k8sutils_test.go @@ -134,7 +134,7 @@ func TestEtcdCommandInvalidClusterMode(t *testing.T) { } } -func TestEtcdCommandDistributedCluster(t *testing.T) { +func TestEtcdCommandDiscoveryCluster(t *testing.T) { dataDir := "/var/etcd/data" etcdMember := &etcdutil.Member{ Name: "etcd-test", @@ -166,13 +166,40 @@ func TestCreateTokenLocalCluster(t *testing.T) { ClusterToken: "testtoken", } - token := createToken(*clusterSpec) + token, _ := createToken(*clusterSpec) if token == "testtoken" { t.Errorf("token should be a randon uuid, instead got %s", token) } } +func TestCreateTokenDiscoveryClusterNoTokenSent(t *testing.T) { + clusterSpec := &api.ClusterSpec{ + Size: 1, + ClusteringMode: "discovery", + } + + _, err := createToken(*clusterSpec) + + if err == nil { + t.Errorf("Expected an error to be thrown when discovery mode on and no token is set") + } +} + +func TestCreateTokenDiscoveryClusterTokenEmpty(t *testing.T) { + clusterSpec := &api.ClusterSpec{ + Size: 1, + ClusteringMode: "discovery", + ClusterToken: "", + } + + _, err := createToken(*clusterSpec) + + if err == nil { + t.Errorf("Expected an error to be thrown when discovery mode on and no token is set") + } +} + func TestCreateTokenDistributedCluster(t *testing.T) { clusterSpec := &api.ClusterSpec{ Size: 1, @@ -180,7 +207,7 @@ func TestCreateTokenDistributedCluster(t *testing.T) { ClusterToken: "testtoken", } - token := createToken(*clusterSpec) + token, _ := createToken(*clusterSpec) if token != "testtoken" { t.Errorf("expected token=%s, got=%s", clusterSpec.ClusterToken, token) From 93f6b02179262af411444e2a739919c4e5dac65d Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 16 Feb 2023 15:59:58 -0300 Subject: [PATCH 07/17] fix: etcd command test when multiple members --- pkg/util/k8sutil/k8sutils_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/util/k8sutil/k8sutils_test.go b/pkg/util/k8sutil/k8sutils_test.go index 484d3b59f..1eacf7296 100644 --- a/pkg/util/k8sutil/k8sutils_test.go +++ b/pkg/util/k8sutil/k8sutils_test.go @@ -99,12 +99,15 @@ func TestEtcdCommandExistingLocalCluster(t *testing.T) { initialEtcdCommand, _ := setupEtcdCommand(dataDir, etcdMember2, strings.Join(memberSetURLs, ","), clusterState, token, "") - expectedCommand := "/usr/local/bin/etcd --data-dir=/var/etcd/data --name=etcd-test-2 --initial-advertise-peer-urls=http://etcd-test-2.etcd-test.etcd.svc.local:2380 " + - "--listen-peer-urls=http://0.0.0.0:2380 --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://etcd-test-2.etcd-test.etcd.svc.local:2379 " + - "--initial-cluster=etcd-test-1=http://etcd-test-1.etcd-test.etcd.svc.local:2380,etcd-test-2=http://etcd-test-2.etcd-test.etcd.svc.local:2380 --initial-cluster-state=existing" - - if initialEtcdCommand != expectedCommand { - t.Errorf("expected command=%s, got=%s", expectedCommand, initialEtcdCommand) + commandBeforeClusterSet := "/usr/local/bin/etcd --data-dir=/var/etcd/data --name=etcd-test-2 --initial-advertise-peer-urls=http://etcd-test-2.etcd-test.etcd.svc.local:2380 " + + "--listen-peer-urls=http://0.0.0.0:2380 --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://etcd-test-2.etcd-test.etcd.svc.local:2379 " + commandClusterSet1 := "--initial-cluster=etcd-test-1=http://etcd-test-1.etcd-test.etcd.svc.local:2380,etcd-test-2=http://etcd-test-2.etcd-test.etcd.svc.local:2380 --initial-cluster-state=existing" + commandClusterSet2 := "--initial-cluster=etcd-test-2=http://etcd-test-2.etcd-test.etcd.svc.local:2380,etcd-test-1=http://etcd-test-1.etcd-test.etcd.svc.local:2380 --initial-cluster-state=existing" + expectedCommand1 := commandBeforeClusterSet+commandClusterSet1 + expectedCommand2 := commandBeforeClusterSet+commandClusterSet2 + + if initialEtcdCommand != expectedCommand1 && initialEtcdCommand != expectedCommand2{ + t.Errorf("wrong etcd command, got=%s", initialEtcdCommand) } } From a0413888406f07c403d491b894850fc07aab5e76 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 7 Mar 2023 17:13:51 -0300 Subject: [PATCH 08/17] Update go-test-e2e.yml --- .github/workflows/go-test-e2e.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go-test-e2e.yml b/.github/workflows/go-test-e2e.yml index e1d10bb40..12b558ca1 100644 --- a/.github/workflows/go-test-e2e.yml +++ b/.github/workflows/go-test-e2e.yml @@ -14,10 +14,11 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2.3.4 - - name: Docker login - run: docker login docker.pkg.github.com -u marlinc -p "${GITHUB_PACKAGE_REGISTRY_TOKEN}" - env: - GITHUB_PACKAGE_REGISTRY_TOKEN: ${{ secrets.GITHUB_PACKAGE_REGISTRY_TOKEN }} + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Prepare e2e image run: | From 13220a8cccff40335f11e2adfa2ff24ca5dc91fb Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 7 Mar 2023 18:02:33 -0300 Subject: [PATCH 09/17] test docker build --- .github/workflows/go-test-e2e.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go-test-e2e.yml b/.github/workflows/go-test-e2e.yml index 12b558ca1..3c92a5338 100644 --- a/.github/workflows/go-test-e2e.yml +++ b/.github/workflows/go-test-e2e.yml @@ -21,10 +21,12 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Prepare e2e image - run: | - hack/build/e2e/docker_push - env: - TEST_IMAGE: docker.pkg.github.com/cbws/etcd-operator/etcd-operator-e2e:${{github.sha}} + uses: docker/build-push-action@v4 + with: + push: true + context: . + file: test/pod/Dockerfile + tags: docker.pkg.github.com/cbws/etcd-operator/etcd-operator-e2e:${{github.sha}} - name: Prepare operator image run: | From 79a92b3ba211b0ca4c48fdaee75f106b65117923 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 7 Mar 2023 18:07:15 -0300 Subject: [PATCH 10/17] setup buildx --- .github/workflows/go-test-e2e.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/go-test-e2e.yml b/.github/workflows/go-test-e2e.yml index 3c92a5338..9bf479653 100644 --- a/.github/workflows/go-test-e2e.yml +++ b/.github/workflows/go-test-e2e.yml @@ -13,6 +13,9 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2.3.4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 - name: Login to Docker Hub uses: docker/login-action@v1 From eb54685825a5432793e3fdbab371247c2a578106 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 7 Mar 2023 18:17:07 -0300 Subject: [PATCH 11/17] setup qemu --- .github/workflows/go-test-e2e.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/go-test-e2e.yml b/.github/workflows/go-test-e2e.yml index 9bf479653..98336c8cd 100644 --- a/.github/workflows/go-test-e2e.yml +++ b/.github/workflows/go-test-e2e.yml @@ -16,6 +16,9 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 - name: Login to Docker Hub uses: docker/login-action@v1 From f9d8164886925d728daaba45104d071300d4745f Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 7 Mar 2023 18:26:12 -0300 Subject: [PATCH 12/17] set platform for e2e --- .github/workflows/go-test-e2e.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/go-test-e2e.yml b/.github/workflows/go-test-e2e.yml index 98336c8cd..b0839c234 100644 --- a/.github/workflows/go-test-e2e.yml +++ b/.github/workflows/go-test-e2e.yml @@ -31,6 +31,7 @@ jobs: with: push: true context: . + platforms: "linux/amd64" file: test/pod/Dockerfile tags: docker.pkg.github.com/cbws/etcd-operator/etcd-operator-e2e:${{github.sha}} From b91975cdc9723fc64e604ac87757641cd16c1e36 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 8 Mar 2023 17:40:45 -0300 Subject: [PATCH 13/17] correct registry --- .github/workflows/go-test-e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go-test-e2e.yml b/.github/workflows/go-test-e2e.yml index b0839c234..793c80c93 100644 --- a/.github/workflows/go-test-e2e.yml +++ b/.github/workflows/go-test-e2e.yml @@ -33,7 +33,7 @@ jobs: context: . platforms: "linux/amd64" file: test/pod/Dockerfile - tags: docker.pkg.github.com/cbws/etcd-operator/etcd-operator-e2e:${{github.sha}} + tags: tfgco/etcd-operator/etcd-operator-e2e:${{github.sha}} - name: Prepare operator image run: | @@ -42,7 +42,7 @@ jobs: hack/build/restore-operator/build IMAGE=${OPERATOR_IMAGE} hack/build/docker_push env: - OPERATOR_IMAGE: docker.pkg.github.com/cbws/etcd-operator/operator:${{github.sha}} + OPERATOR_IMAGE: tfgco/etcd-operator/operator:${{github.sha}} test-e2e: name: E2E runs-on: ubuntu-latest From 570bc1268fab802cf426cf33f4ab05e9ade3fdd4 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 8 Mar 2023 18:20:11 -0300 Subject: [PATCH 14/17] correct tags --- .github/workflows/go-test-e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go-test-e2e.yml b/.github/workflows/go-test-e2e.yml index 793c80c93..d38cefd27 100644 --- a/.github/workflows/go-test-e2e.yml +++ b/.github/workflows/go-test-e2e.yml @@ -33,7 +33,7 @@ jobs: context: . platforms: "linux/amd64" file: test/pod/Dockerfile - tags: tfgco/etcd-operator/etcd-operator-e2e:${{github.sha}} + tags: tfgco/etcd-operator-e2e:${{github.sha}} - name: Prepare operator image run: | @@ -42,7 +42,7 @@ jobs: hack/build/restore-operator/build IMAGE=${OPERATOR_IMAGE} hack/build/docker_push env: - OPERATOR_IMAGE: tfgco/etcd-operator/operator:${{github.sha}} + OPERATOR_IMAGE: tfgco/etcd-operator:${{github.sha}} test-e2e: name: E2E runs-on: ubuntu-latest From 9e7b1bb22e537d12a0dc4e2ef2e86e3409d8fe94 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 9 Mar 2023 09:43:52 -0300 Subject: [PATCH 15/17] setup kind --- .github/workflows/go-test-e2e.yml | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/go-test-e2e.yml b/.github/workflows/go-test-e2e.yml index d38cefd27..a989c4a2f 100644 --- a/.github/workflows/go-test-e2e.yml +++ b/.github/workflows/go-test-e2e.yml @@ -31,18 +31,23 @@ jobs: with: push: true context: . - platforms: "linux/amd64" file: test/pod/Dockerfile tags: tfgco/etcd-operator-e2e:${{github.sha}} - + - name: Prepare operator image run: | hack/build/operator/build hack/build/backup-operator/build hack/build/restore-operator/build - IMAGE=${OPERATOR_IMAGE} hack/build/docker_push - env: - OPERATOR_IMAGE: tfgco/etcd-operator:${{github.sha}} + + - name: Prepare operator image + uses: docker/build-push-action@v4 + with: + push: true + context: . + file: hack/build/Dockerfile + tags: tfgco/etcd-operator:${{github.sha}} + test-e2e: name: E2E runs-on: ubuntu-latest @@ -57,12 +62,17 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2.3.4 + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: KinD (Kubernetes in Docker) Action uses: engineerd/setup-kind@v0.5.0 - + - name: Test run: | - docker login docker.pkg.github.com -u marlinc -p "${GITHUB_PACKAGE_REGISTRY_TOKEN}" docker pull $TEST_IMAGE docker pull $OPERATOR_IMAGE export KUBECONFIG="${HOME}/.kube/config" @@ -71,13 +81,13 @@ jobs: hack/ci/run_e2e env: GITHUB_PACKAGE_REGISTRY_TOKEN: ${{ secrets.GITHUB_PACKAGE_REGISTRY_TOKEN }} - OPERATOR_IMAGE: docker.pkg.github.com/cbws/etcd-operator/operator:${{github.sha}} + OPERATOR_IMAGE: tfgco/etcd-operator:${{github.sha}} TEST_AWS_SECRET: na TEST_S3_BUCKET: na TEST_NAMESPACE: default BUILD_IMAGE: false BUILD_E2E: false - TEST_IMAGE: docker.pkg.github.com/cbws/etcd-operator/etcd-operator-e2e:${{github.sha}} + TEST_IMAGE: tfgco/etcd-operator-e2e:${{github.sha}} PASSES: e2e - name: Show logs From a72ae5b6317fbf71ac5c9aac72e243e35bc19bc7 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 15 Mar 2023 15:35:05 -0300 Subject: [PATCH 16/17] force newest version of kind --- .github/workflows/go-test-e2e.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/go-test-e2e.yml b/.github/workflows/go-test-e2e.yml index a989c4a2f..95202a216 100644 --- a/.github/workflows/go-test-e2e.yml +++ b/.github/workflows/go-test-e2e.yml @@ -70,6 +70,8 @@ jobs: - name: KinD (Kubernetes in Docker) Action uses: engineerd/setup-kind@v0.5.0 + with: + version: "v0.17.0" - name: Test run: | From 36f42caa4c4f64f81d3cc747812ff2b11790f656 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 16 Mar 2023 09:52:01 -0300 Subject: [PATCH 17/17] correct rbac api version of e2e test resources --- example/rbac/cluster-role-binding-template.yaml | 2 +- example/rbac/cluster-role-template.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/rbac/cluster-role-binding-template.yaml b/example/rbac/cluster-role-binding-template.yaml index bee0ed128..483c6b0da 100644 --- a/example/rbac/cluster-role-binding-template.yaml +++ b/example/rbac/cluster-role-binding-template.yaml @@ -1,4 +1,4 @@ -apiVersion: rbac.authorization.k8s.io/v1beta1 +apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: diff --git a/example/rbac/cluster-role-template.yaml b/example/rbac/cluster-role-template.yaml index fa7a41e75..0a82e6a2a 100644 --- a/example/rbac/cluster-role-template.yaml +++ b/example/rbac/cluster-role-template.yaml @@ -1,4 +1,4 @@ -apiVersion: rbac.authorization.k8s.io/v1beta1 +apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: