Skip to content

Commit

Permalink
tests: Remove ClusterIP logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Jul 15, 2017
1 parent 1a2191d commit 56c1785
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 10 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ KUBECONFIG?=$(HOME)/.kube/config
PROMU := $(GOPATH)/bin/promu
PREFIX ?= $(shell pwd)

CLUSTER_IP?=$(kubectl config view --minify | grep server: | cut -f 3 -d ":" | tr -d "//")

pkgs = $(shell go list ./... | grep -v /vendor/ | grep -v /test/)

all: check-license format build test
Expand All @@ -31,7 +29,7 @@ container:
docker build -t $(REPO):$(TAG) .

e2e-test:
go test -timeout 20m -v ./test/e2e/ $(TEST_RUN_ARGS) --kubeconfig=$(KUBECONFIG) --operator-image=$(REPO):$(TAG) --namespace=$(NAMESPACE) --cluster-ip=$(CLUSTER_IP)
go test -timeout 20m -v ./test/e2e/ $(TEST_RUN_ARGS) --kubeconfig=$(KUBECONFIG) --operator-image=$(REPO):$(TAG) --namespace=$(NAMESPACE)

e2e-status:
kubectl get prometheus,alertmanager,servicemonitor,statefulsets,deploy,svc,endpoints,pods,cm,secrets,replicationcontrollers --all-namespaces
Expand Down
8 changes: 3 additions & 5 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ type Framework struct {
MasterHost string
Namespace *v1.Namespace
OperatorPod *v1.Pod
ClusterIP string
DefaultTimeout time.Duration
}

// Setup setups a test framework and returns it.
func New(ns, kubeconfig, opImage, ip string) (*Framework, error) {
func New(ns, kubeconfig, opImage string) (*Framework, error) {
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
return nil, errors.Wrap(err, "build config from flags failed")
Expand Down Expand Up @@ -75,7 +74,6 @@ func New(ns, kubeconfig, opImage, ip string) (*Framework, error) {
MonClient: mclient,
HTTPClient: httpc,
Namespace: namespace,
ClusterIP: ip,
DefaultTimeout: time.Minute,
}

Expand Down Expand Up @@ -158,8 +156,8 @@ func (ctx *TestCtx) SetupPrometheusRBAC(t *testing.T, ns string, kubeClient kube
ctx.AddFinalizerFn(finalizerFn)
}

if finalizerFn, err := CreateClusterRoleBinding(kubeClient, ns, "../../example/rbac/prometheus/prometheus-cluster-role-binding.yaml"); err != nil {
t.Fatal(errors.Wrap(err, "failed to create prometheus cluster role binding"))
if finalizerFn, err := CreateRoleBinding(kubeClient, ns, "framework/ressources/prometheus-role-binding.yml"); err != nil {
t.Fatal(errors.Wrap(err, "failed to create prometheus role binding"))
} else {
ctx.AddFinalizerFn(finalizerFn)
}
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/framework/ressources/prometheus-role-binding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: prometheus
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: prometheus
subjects:
- kind: ServiceAccount
name: prometheus
60 changes: 60 additions & 0 deletions test/e2e/framework/role-binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2017 The prometheus-operator Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package framework

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/kubernetes"
rbacv1alpha1 "k8s.io/client-go/pkg/apis/rbac/v1alpha1"
)

func CreateRoleBinding(kubeClient kubernetes.Interface, ns string, relativePath string) (finalizerFn, error) {
finalizerFn := func() error { return DeleteRoleBinding(kubeClient, ns, relativePath) }
roleBinding, err := parseRoleBindingYaml(relativePath)
if err != nil {
return finalizerFn, err
}

_, err = kubeClient.RbacV1alpha1().RoleBindings(ns).Create(roleBinding)
return finalizerFn, err
}

func DeleteRoleBinding(kubeClient kubernetes.Interface, ns string, relativePath string) error {
roleBinding, err := parseRoleBindingYaml(relativePath)
if err != nil {
return err
}

if err := kubeClient.RbacV1alpha1().RoleBindings(ns).Delete(roleBinding.Name, &metav1.DeleteOptions{}); err != nil {
return err
}

return nil
}

func parseRoleBindingYaml(relativePath string) (*rbacv1alpha1.RoleBinding, error) {
manifest, err := PathToOSFile(relativePath)
if err != nil {
return nil, err
}

roleBinding := rbacv1alpha1.RoleBinding{}
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&roleBinding); err != nil {
return nil, err
}

return &roleBinding, nil
}
3 changes: 1 addition & 2 deletions test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ func TestMain(m *testing.M) {
kubeconfig := flag.String("kubeconfig", "", "kube config path, e.g. $HOME/.kube/config")
opImage := flag.String("operator-image", "", "operator image, e.g. quay.io/coreos/prometheus-operator")
ns := flag.String("namespace", "prometheus-operator-e2e-tests", "e2e test namespace")
ip := flag.String("cluster-ip", "", "ip of the kubernetes cluster to use for external requests")
flag.Parse()

var (
err error
code int = 0
)

if framework, err = operatorFramework.New(*ns, *kubeconfig, *opImage, *ip); err != nil {
if framework, err = operatorFramework.New(*ns, *kubeconfig, *opImage); err != nil {
log.Printf("failed to setup framework: %v\n", err)
os.Exit(1)
}
Expand Down

0 comments on commit 56c1785

Please sign in to comment.