Repair e2e tests
Fix e2e tests issues caused by validation webhook
MODIFY
e2e-tests/limits/run
e2e-tests/limits/run
@@ -37,21 +37,6 @@ check_cr_config() {
-f $test_dir/conf/$cluster.yml
}
-no_storage() {
- local cluster="no-storage"
-
- # apply cr config
- apply_config $test_dir/conf/$cluster.yml
-
- # check operator logs
- kubectl_bin logs $(get_operator_pod) ${OPERATOR_NS:+-n $OPERATOR_NS} \
- | grep "volume.resources.storage can't be empty"
-
- # delete cluster
- kubectl_bin delete \
- -f $test_dir/conf/$cluster.yml
-}
-
main() {
create_infra $namespace
kubectl_bin apply -f $conf_dir/secrets.yml
@@ -65,9 +50,6 @@ main() {
desc 'check if possible to create cluster without CPU/Memory requests and limits'
check_cr_config "no-requests-no-limits"
- desc 'check if possible to create cluster without storage size'
- no_storage
-
destroy $namespace
}

MODIFY
e2e-tests/one-pod/conf/one-pod.yml
e2e-tests/one-pod/conf/one-pod.yml
@@ -8,7 +8,6 @@ spec:
pause: false
pxc:
size: 1
- allowUnsafeConfigurations: true
image: -pxc
configuration: |
[mysqld]

MODIFY
e2e-tests/operator-self-healing/run
e2e-tests/operator-self-healing/run
@@ -87,6 +87,10 @@ netem_pod() {
main() {
create_infra $namespace
+
+ kubectl_bin patch clusterrole percona-xtradb-cluster-operator --type=json -p '[{"op":"remove","path":"/rules/1"}]'
+ kubectl_bin delete validatingwebhookconfigurations.admissionregistration.k8s.io percona-xtradbcluster-webhook
+
kubectl_bin apply -f "$test_dir/conf/pumba.yml" ${OPERATOR_NS:+-n $OPERATOR_NS}
desc 'create PXC cluster'

MODIFY
e2e-tests/self-healing/compare/proxy-vars-80.sql
e2e-tests/self-healing/compare/proxy-vars-80.sql
@@ -30,7 +30,7 @@ admin-stats_system_memory 60
admin-telnet_admin_ifaces (null)
admin-telnet_stats_ifaces (null)
admin-vacuum_stats true
-admin-version 2.0.14-percona-1.1
+admin-version 2.0.15-percona-1.1
admin-web_enabled false
admin-web_port 6080
mysql-add_ldap_user_comment
@@ -88,6 +88,7 @@ mysql-max_allowed_packet 67108864
mysql-max_connections 2048
mysql-max_stmts_cache 10000
mysql-max_stmts_per_connection 20
+mysql-max_transaction_idle_time 14400000
mysql-max_transaction_time 14400000
mysql-min_num_servers_lantency_awareness 1000
mysql-mirror_max_concurrency 16

RENAME
e2e-tests/limits/conf/no-storage.yml
e2e-tests/validation-hook/conf/cr-with-no-storage.yaml
@@ -9,34 +9,34 @@ spec:
pxc:
size: 3
image: -pxc
- volumeSpec:
+# volumeSpec:
# emptyDir: {}
# hostPath:
# path: /data
# type: Directory
# persistentVolumeClaim:
# storageClassName: standard
- accessModes: [ "ReadWriteOnce" ]
- resources:
- requests:
- storage: 6Gi
+# accessModes: [ "ReadWriteOnce" ]
+# resources:
+# requests:
+# storage: 6Gi
affinity:
antiAffinityTopologyKey: none
proxysql:
enabled: true
size: 1
image: -proxysql
- volumeSpec:
+# volumeSpec:
# emptyDir: {}
# hostPath:
# path: /data
# type: Directory
# persistentVolumeClaim:
# storageClassName: standard
- accessModes: [ "ReadWriteOnce" ]
- resources:
- requests:
- storage: 6Gi
+# accessModes: [ "ReadWriteOnce" ]
+# resources:
+# requests:
+# storage: 6Gi
affinity:
antiAffinityTopologyKey: none
pmm:

MODIFY
e2e-tests/validation-hook/run
e2e-tests/validation-hook/run
@@ -23,4 +23,11 @@ if [[ $output != *"can't enable both HAProxy and ProxySQL"* ]]; then
exit 1
fi
+output=$(kubectl 2>&1 apply -f "$test_dir/conf/cr-with-no-storage.yaml")
+
+if [[ $output != *"PXC: volumeSpec should be specified"* ]]; then
+ echo 'invalid hook response'
+ exit 1
+fi
+
destroy $namespace

MODIFY
pkg/controller/pxc/backup.go
pkg/controller/pxc/backup.go
@@ -13,12 +13,13 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
api "github.com/percona/percona-xtradb-cluster-operator/pkg/apis/pxc/v1"
+ "github.com/percona/percona-xtradb-cluster-operator/pkg/k8s"
"github.com/percona/percona-xtradb-cluster-operator/pkg/pxc/backup"
)
func (r *ReconcilePerconaXtraDBCluster) reconcileBackups(cr *api.PerconaXtraDBCluster) error {
backups := make(map[string]api.PXCScheduledBackupSchedule)
- operatorPod, err := r.operatorPod()
+ operatorPod, err := k8s.OperatorPod(r.client)
if err != nil {
return errors.Wrap(err, "get operator deployment")
}

MODIFY
pkg/controller/pxc/controller.go
pkg/controller/pxc/controller.go
@@ -4,8 +4,6 @@ import (
"context"
"crypto/md5"
"fmt"
- "io/ioutil"
- "os"
"strings"
"sync"
"sync/atomic"
@@ -33,6 +31,7 @@ import (
"github.com/percona/percona-xtradb-cluster-operator/clientcmd"
api "github.com/percona/percona-xtradb-cluster-operator/pkg/apis/pxc/v1"
+ "github.com/percona/percona-xtradb-cluster-operator/pkg/k8s"
"github.com/percona/percona-xtradb-cluster-operator/pkg/pxc"
"github.com/percona/percona-xtradb-cluster-operator/pkg/pxc/app/config"
"github.com/percona/percona-xtradb-cluster-operator/pkg/pxc/app/statefulset"
@@ -258,7 +257,7 @@ func (r *ReconcilePerconaXtraDBCluster) Reconcile(request reconcile.Request) (re
return reconcile.Result{}, err
}
- operatorPod, err := r.operatorPod()
+ operatorPod, err := k8s.OperatorPod(r.client)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "get operator deployment")
}
@@ -525,26 +524,6 @@ func (r *ReconcilePerconaXtraDBCluster) Reconcile(request reconcile.Request) (re
return rr, nil
}
-func (r *ReconcilePerconaXtraDBCluster) operatorPod() (corev1.Pod, error) {
- operatorPod := corev1.Pod{}
-
- nsBytes, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
- if err != nil {
- return operatorPod, err
- }
-
- ns := strings.TrimSpace(string(nsBytes))
-
- if err := r.client.Get(context.TODO(), types.NamespacedName{
- Namespace: ns,
- Name: os.Getenv("HOSTNAME"),
- }, &operatorPod); err != nil {
- return operatorPod, err
- }
-
- return operatorPod, nil
-}
-
func (r *ReconcilePerconaXtraDBCluster) deploy(cr *api.PerconaXtraDBCluster) error {
stsApp := statefulset.NewNode(cr)
err := r.reconcileConfigMap(cr)
@@ -552,7 +531,7 @@ func (r *ReconcilePerconaXtraDBCluster) deploy(cr *api.PerconaXtraDBCluster) err
return err
}
- operatorPod, err := r.operatorPod()
+ operatorPod, err := k8s.OperatorPod(r.client)
if err != nil {
return errors.Wrap(err, "get operator deployment")
}

ADD
pkg/k8s/operator_pod.go
+package k8s
+
+import (
+ "context"
+ "io/ioutil"
+ "os"
+ "strings"
+
+ corev1 "k8s.io/api/core/v1"
+ "k8s.io/apimachinery/pkg/types"
+ "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+func OperatorPod(cl client.Client) (corev1.Pod, error) {
+ operatorPod := corev1.Pod{}
+
+ nsBytes, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
+ if err != nil {
+ return operatorPod, err
+ }
+
+ ns := strings.TrimSpace(string(nsBytes))
+
+ if err := cl.Get(context.TODO(), types.NamespacedName{
+ Namespace: ns,
+ Name: os.Getenv("HOSTNAME"),
+ }, &operatorPod); err != nil {
+ return operatorPod, err
+ }
+
+ return operatorPod, nil
+}

MODIFY
pkg/webhook/hook.go
pkg/webhook/hook.go
@@ -14,12 +14,14 @@ import (
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
+ "k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/util/cert"
"sigs.k8s.io/controller-runtime/pkg/client"
log "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
v1 "github.com/percona/percona-xtradb-cluster-operator/pkg/apis/pxc/v1"
+ "github.com/percona/percona-xtradb-cluster-operator/pkg/k8s"
"github.com/percona/percona-xtradb-cluster-operator/pkg/pxctls"
)
@@ -34,7 +36,11 @@ type hook struct {
}
func (h *hook) Start(i <-chan struct{}) error {
- err := h.createWebhook()
+ err := h.createService()
+ if err != nil {
+ log.Log.Info("Can't create service", "err", err.Error())
+ }
+ err = h.createWebhook()
if err != nil {
log.Log.Info("Can't create webhook", "error", err.Error())
}
@@ -42,6 +48,42 @@ func (h *hook) Start(i <-chan struct{}) error {
return nil
}
+func (h *hook) createService() error {
+ opPod, err := k8s.OperatorPod(h.cl)
+ if err != nil {
+ return errors.Wrap(err, "get operator pod")
+ }
+ svc := &corev1.Service{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "percona-xtradb-cluster-operator",
+ Namespace: h.namespace,
+ Labels: map[string]string{"name": "percona-xtradb-cluster-operator"},
+ },
+ Spec: corev1.ServiceSpec{
+ Ports: []corev1.ServicePort{{Port: 443, TargetPort: intstr.FromInt(9443)}},
+ Selector: opPod.Labels,
+ },
+ }
+ err = h.cl.Create(context.TODO(), svc)
+ if err != nil {
+ if k8serrors.IsAlreadyExists(err) {
+ service := &corev1.Service{}
+ err = h.cl.Get(context.TODO(), types.NamespacedName{
+ Name: "percona-xtradb-cluster-operator",
+ Namespace: h.namespace,
+ }, service)
+ if err != nil {
+ return err
+ }
+
+ service.Spec.Selector = opPod.Labels
+ return h.cl.Update(context.TODO(), service)
+ }
+ return err
+ }
+ return nil
+}
+
func (h *hook) createWebhook() error {
failPolicy := admissionregistration.Fail
sideEffects := admissionregistration.SideEffectClassNone

K8SPXC-537: Repair e2e tests (#672)

Fix e2e tests issues caused by validation webhook