Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
viovanov committed Dec 11, 2018
1 parent 04fcf1a commit f8df5ff
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ test-integration:
bin/test-integration

test-e2e:
bin/test-integration
bin/test-e2e

test: vet lint test-unit test-integration test-e2e

tools:
bin/tools
bin/tools
65 changes: 40 additions & 25 deletions integration/environment/machine.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package environment

import (
"fmt"
"time"

"github.com/pkg/errors"
apiv1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"

bdcv1 "code.cloudfoundry.org/cf-operator/pkg/kube/apis/boshdeploymentcontroller/v1alpha1"
essv1 "code.cloudfoundry.org/cf-operator/pkg/kube/apis/extendedstatefulsetcontroller/v1alpha1"
bdcv1 "code.cloudfoundry.org/cf-operator/pkg/kube/apis/boshdeployment/v1alpha1"
essv1 "code.cloudfoundry.org/cf-operator/pkg/kube/apis/extendedstatefulset/v1alpha1"
"code.cloudfoundry.org/cf-operator/pkg/kube/client/clientset/versioned"
)

Expand Down Expand Up @@ -51,7 +51,7 @@ func (m *Machine) WaitForExtendedStatefulSets(namespace string, labels string) e

// ExtendedStatefulSetExists returns true if at least one ess selected by labels exists
func (m *Machine) ExtendedStatefulSetExists(namespace string, labels string) (bool, error) {
esss, err := m.VersionedClientset.ExtendedstatefulsetcontrollerV1alpha1().ExtendedStatefulSets(namespace).List(v1.ListOptions{
esss, err := m.VersionedClientset.ExtendedstatefulsetV1alpha1().ExtendedStatefulSets(namespace).List(metav1.ListOptions{
LabelSelector: labels,
})
if err != nil {
Expand All @@ -61,7 +61,6 @@ func (m *Machine) ExtendedStatefulSetExists(namespace string, labels string) (bo
return len(esss.Items) > 0, nil
}


// WaitForPodsDelete blocks until the pod is deleted. It fails after the timeout.
func (m *Machine) WaitForPodsDelete(namespace string) error {
return wait.PollImmediate(m.pollInterval, m.pollTimeout, func() (bool, error) {
Expand All @@ -83,15 +82,15 @@ func (m *Machine) PodsDeleted(namespace string) (bool, error) {

// PodRunning returns true if the pod by that name is in state running
func (m *Machine) PodRunning(namespace string, name string) (bool, error) {
pod, err := m.Clientset.CoreV1().Pods(namespace).Get(name, v1.GetOptions{})
pod, err := m.Clientset.CoreV1().Pods(namespace).Get(name, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
return false, nil
}
return false, errors.Wrapf(err, "failed to query for pod by name: %s", name)
}

if pod.Status.Phase == apiv1.PodRunning {
if pod.Status.Phase == corev1.PodRunning {
return true, nil
}
return false, nil
Expand All @@ -101,7 +100,7 @@ func (m *Machine) PodRunning(namespace string, name string) (bool, error) {
// Note that only the first page of pods is considered - don't use this if you have a
// long pod list that you care about
func (m *Machine) PodsRunning(namespace string, labels string) (bool, error) {
pods, err := m.Clientset.CoreV1().Pods(namespace).List(v1.ListOptions{
pods, err := m.Clientset.CoreV1().Pods(namespace).List(metav1.ListOptions{
LabelSelector: labels,
})
if err != nil {
Expand All @@ -113,7 +112,7 @@ func (m *Machine) PodsRunning(namespace string, labels string) (bool, error) {
}

for _, pod := range pods.Items {
if pod.Status.Phase != apiv1.PodRunning {
if pod.Status.Phase != corev1.PodRunning {
return false, nil
}
}
Expand All @@ -131,8 +130,8 @@ func (m *Machine) WaitForBOSHDeploymentDeletion(namespace string, name string) e

// HasBOSHDeployment returns true if the pod by that name is in state running
func (m *Machine) HasBOSHDeployment(namespace string, name string) (bool, error) {
client := m.VersionedClientset.Boshdeploymentcontroller().BOSHDeployments(namespace)
_, err := client.Get(name, v1.GetOptions{})
client := m.VersionedClientset.Boshdeployment().BOSHDeployments(namespace)
_, err := client.Get(name, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
return false, nil
Expand All @@ -148,7 +147,7 @@ func (m *Machine) CreateConfigMap(namespace string, configMap corev1.ConfigMap)
client := m.Clientset.CoreV1().ConfigMaps(namespace)
_, err := client.Create(&configMap)
return func() {
client.Delete(configMap.GetName(), &v1.DeleteOptions{})
client.Delete(configMap.GetName(), &metav1.DeleteOptions{})
}, err
}

Expand All @@ -157,54 +156,70 @@ func (m *Machine) CreateSecret(namespace string, secret corev1.Secret) (TearDown
client := m.Clientset.CoreV1().Secrets(namespace)
_, err := client.Create(&secret)
return func() {
client.Delete(secret.GetName(), &v1.DeleteOptions{})
client.Delete(secret.GetName(), &metav1.DeleteOptions{})
}, err
}

// CreateBOSHDeployment creates a BOSHDeployment custom resource and returns a function to delete it
func (m *Machine) CreateBOSHDeployment(namespace string, deployment bdcv1.BOSHDeployment) (*bdcv1.BOSHDeployment, TearDownFunc, error) {
client := m.VersionedClientset.Boshdeploymentcontroller().BOSHDeployments(namespace)
client := m.VersionedClientset.Boshdeployment().BOSHDeployments(namespace)
d, err := client.Create(&deployment)
return d, func() {
client.Delete(deployment.GetName(), &v1.DeleteOptions{})
client.Delete(deployment.GetName(), &metav1.DeleteOptions{})
}, err
}

// UpdateBOSHDeployment creates a BOSHDeployment custom resource and returns a function to delete it
func (m *Machine) UpdateBOSHDeployment(namespace string, deployment bdcv1.BOSHDeployment) (*bdcv1.BOSHDeployment, TearDownFunc, error) {
client := m.VersionedClientset.Boshdeploymentcontroller().BOSHDeployments(namespace)
client := m.VersionedClientset.BoshdeploymentV1alpha1().BOSHDeployments(namespace)
d, err := client.Update(&deployment)
return d, func() {
client.Delete(deployment.GetName(), &v1.DeleteOptions{})
client.Delete(deployment.GetName(), &metav1.DeleteOptions{})
}, err
}

// DeleteBOSHDeployment deletes a BOSHDeployment custom resource
func (m *Machine) DeleteBOSHDeployment(namespace string, name string) error {
client := m.VersionedClientset.Boshdeploymentcontroller().BOSHDeployments(namespace)
return client.Delete(name, &v1.DeleteOptions{})
client := m.VersionedClientset.BoshdeploymentV1alpha1().BOSHDeployments(namespace)
return client.Delete(name, &metav1.DeleteOptions{})
}

// CreateExtendedStatefulSet creates a ExtendedStatefulSet custom resource and returns a function to delete it
func (m *Machine) CreateExtendedStatefulSet(namespace string, ess essv1.ExtendedStatefulSet) (*essv1.ExtendedStatefulSet, TearDownFunc, error) {
client := m.VersionedClientset.Extendedstatefulsetcontroller().ExtendedStatefulSets(namespace)
client := m.VersionedClientset.ExtendedstatefulsetV1alpha1().ExtendedStatefulSets(namespace)
d, err := client.Create(&ess)
return d, func() {
client.Delete(ess.GetName(), &v1.DeleteOptions{})
client.Delete(ess.GetName(), &metav1.DeleteOptions{})
}, err
}

// UpdateExtendedStatefulSet creates a ExtendedStatefulSet custom resource and returns a function to delete it
func (m *Machine) UpdateExtendedStatefulSet(namespace string, ess essv1.ExtendedStatefulSet) (*essv1.ExtendedStatefulSet, TearDownFunc, error) {
client := m.VersionedClientset.Extendedstatefulsetcontroller().ExtendedStatefulSets(namespace)
client := m.VersionedClientset.ExtendedstatefulsetV1alpha1().ExtendedStatefulSets(namespace)
d, err := client.Update(&ess)
return d, func() {
client.Delete(ess.GetName(), &v1.DeleteOptions{})
client.Delete(ess.GetName(), &metav1.DeleteOptions{})
}, err
}

// DeleteExtendedStatefulSet deletes a ExtendedStatefulSet custom resource
func (m *Machine) DeleteExtendedStatefulSet(namespace string, name string) error {
client := m.VersionedClientset.Extendedstatefulsetcontroller().ExtendedStatefulSets(namespace)
return client.Delete(name, &v1.DeleteOptions{})
client := m.VersionedClientset.ExtendedstatefulsetV1alpha1().ExtendedStatefulSets(namespace)
return client.Delete(name, &metav1.DeleteOptions{})
}

// PodLabeled returns true if the pod is labeled correctly
func (m *Machine) PodLabeled(namespace string, name string, desiredLabel, desiredValue string) (bool, error) {
pod, err := m.Clientset.CoreV1().Pods(namespace).Get(name, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
return false, err
}
return false, errors.Wrapf(err, "Failed to query for pod by name: %s", name)
}

if pod.ObjectMeta.Labels[desiredLabel] == desiredValue {
return true, nil
}
return false, fmt.Errorf("Cannot match the desired label with %s", desiredValue)
}
2 changes: 1 addition & 1 deletion pkg/kube/controllers/controllers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controller
package controllers

import (
"go.uber.org/zap"
Expand Down

0 comments on commit f8df5ff

Please sign in to comment.