1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 03:38:43 +00:00

tests: Remove ClusterIP logic

This commit is contained in:
Max Leonard Inden 2017-07-14 16:06:30 +02:00
parent 1a2191df98
commit 56c1785409
No known key found for this signature in database
GPG key ID: 5403C5464810BC26
5 changed files with 76 additions and 10 deletions

View file

@ -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
@ -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

View file

@ -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")
@ -75,7 +74,6 @@ func New(ns, kubeconfig, opImage, ip string) (*Framework, error) {
MonClient: mclient,
HTTPClient: httpc,
Namespace: namespace,
ClusterIP: ip,
DefaultTimeout: time.Minute,
}
@ -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)
}

View file

@ -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

View file

@ -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
}

View file

@ -32,7 +32,6 @@ 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 (
@ -40,7 +39,7 @@ func TestMain(m *testing.M) {
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)
}