Skip to content

Commit

Permalink
Remove PodPreset embedding from Binding (openshift#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilebox committed Aug 7, 2017
1 parent 1abdcc8 commit 8887561
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 233 deletions.
14 changes: 0 additions & 14 deletions contrib/examples/walkthrough/ups-binding-pp.yaml

This file was deleted.

22 changes: 0 additions & 22 deletions pkg/apis/servicecatalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,28 +413,6 @@ type BindingSpec struct {
//
// Immutable.
ExternalID string

// Currently, this field is ALPHA: it may change or disappear at any time
// and its data will not be migrated.
//
// AlphaPodPresetTemplate describes how a PodPreset should be created once
// the Binding has been made. If supplied, a PodPreset will be created
// using information in this field once the Binding has been made in the
// Broker. The PodPreset will use the EnvFrom feature to expose the keys
// from the Secret (specified by SecretName) that holds the Binding
// information into Pods.
//
// In the future, we will provide a higher degree of control over the PodPreset.
AlphaPodPresetTemplate *AlphaPodPresetTemplate
}

// AlphaPodPresetTemplate represents how a PodPreset should be created for a
// Binding.
type AlphaPodPresetTemplate struct {
// Name is the name of the PodPreset to create.
Name string
// Selector is the LabelSelector of the PodPreset to create.
Selector metav1.LabelSelector
}

// BindingStatus represents the current status of a Binding.
Expand Down
22 changes: 0 additions & 22 deletions pkg/apis/servicecatalog/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,28 +414,6 @@ type BindingSpec struct {
//
// Immutable.
ExternalID string `json:"externalID"`

// Currently, this field is ALPHA: it may change or disappear at any time
// and its data will not be migrated.
//
// AlphaPodPresetTemplate describes how a PodPreset should be created once
// the Binding has been made. If supplied, a PodPreset will be created
// using information in this field once the Binding has been made in the
// Broker. The PodPreset will use the EnvFrom feature to expose the keys
// from the Secret (specified by SecretName) that holds the Binding
// information into Pods.
//
// In the future, we will provide a higher degree of control over the PodPreset.
AlphaPodPresetTemplate *AlphaPodPresetTemplate `json:"alphaPodPresetTemplate,omitempty"`
}

// AlphaPodPresetTemplate represents how a PodPreset should be created for a
// Binding.
type AlphaPodPresetTemplate struct {
// Name is the name of the PodPreset to create.
Name string `json:"name"`
// Selector is the LabelSelector of the PodPreset to create.
Selector metav1.LabelSelector `json:"selector"`
}

// BindingStatus represents the current status of a Binding.
Expand Down
9 changes: 0 additions & 9 deletions pkg/apis/servicecatalog/validation/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package validation

import (
apivalidation "k8s.io/apimachinery/pkg/api/validation"
metav1validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
"k8s.io/apimachinery/pkg/util/validation/field"

sc "github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog"
Expand Down Expand Up @@ -53,14 +52,6 @@ func validateBindingSpec(spec *sc.BindingSpec, fldPath *field.Path, create bool)
allErrs = append(allErrs, field.Invalid(fldPath.Child("secretName"), spec.SecretName, msg))
}

if spec.AlphaPodPresetTemplate != nil {
allErrs = append(allErrs, metav1validation.ValidateLabelSelector(&spec.AlphaPodPresetTemplate.Selector, fldPath.Child("alphaPodPresetTemplate", "selector"))...)

for _, msg := range apivalidation.NameIsDNSSubdomain(spec.AlphaPodPresetTemplate.Name, false /* prefix */) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("alphaPodPresetTemplate", "name"), spec.AlphaPodPresetTemplate.Name, msg))
}
}

return allErrs
}

Expand Down
22 changes: 0 additions & 22 deletions pkg/apis/servicecatalog/validation/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,6 @@ func TestValidateBinding(t *testing.T) {
}(),
valid: false,
},
{
name: "invalid alphaPodPresetTemplate.name",
binding: func() *servicecatalog.Binding {
b := validBinding()
b.Spec.AlphaPodPresetTemplate = &servicecatalog.AlphaPodPresetTemplate{
Name: "T_T",
}
return b
}(),
valid: false,
},
{
name: "invalid alphaPodPresetTemplate.selector",
binding: func() *servicecatalog.Binding {
b := validBinding()
b.Spec.AlphaPodPresetTemplate = &servicecatalog.AlphaPodPresetTemplate{
Selector: metav1.LabelSelector{},
}
return b
}(),
valid: false,
},
}

for _, tc := range cases {
Expand Down
34 changes: 0 additions & 34 deletions pkg/controller/controller_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/pkg/api"
"k8s.io/client-go/pkg/api/v1"
settingsv1alpha1 "k8s.io/client-go/pkg/apis/settings/v1alpha1"
"k8s.io/client-go/tools/cache"
)

Expand Down Expand Up @@ -462,45 +461,12 @@ func (c *controller) injectBinding(binding *v1alpha1.Binding, credentials map[st
}
}

if binding.Spec.AlphaPodPresetTemplate == nil {
return nil
}

podPreset := &settingsv1alpha1.PodPreset{
ObjectMeta: metav1.ObjectMeta{
Name: binding.Spec.AlphaPodPresetTemplate.Name,
Namespace: binding.Namespace,
},
Spec: settingsv1alpha1.PodPresetSpec{
Selector: binding.Spec.AlphaPodPresetTemplate.Selector,
EnvFrom: []v1.EnvFromSource{
{
SecretRef: &v1.SecretEnvSource{
LocalObjectReference: v1.LocalObjectReference{
Name: binding.Spec.SecretName,
},
},
},
},
},
}

_, err = c.kubeClient.SettingsV1alpha1().PodPresets(binding.Namespace).Create(podPreset)
return err
}

func (c *controller) ejectBinding(binding *v1alpha1.Binding) error {
var err error

if binding.Spec.AlphaPodPresetTemplate != nil {
podPresetName := binding.Spec.AlphaPodPresetTemplate.Name
glog.V(5).Infof("Deleting PodPreset %v/%v", binding.Namespace, podPresetName)
err := c.kubeClient.SettingsV1alpha1().PodPresets(binding.Namespace).Delete(podPresetName, &metav1.DeleteOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return err
}
}

glog.V(5).Infof("Deleting Secret %v/%v", binding.Namespace, binding.Spec.SecretName)
err = c.kubeClient.Core().Secrets(binding.Namespace).Delete(binding.Spec.SecretName, &metav1.DeleteOptions{})
if err != nil && !apierrors.IsNotFound(err) {
Expand Down
110 changes: 0 additions & 110 deletions pkg/controller/controller_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (

"k8s.io/client-go/pkg/api"
"k8s.io/client-go/pkg/api/v1"
settingsv1alpha1 "k8s.io/client-go/pkg/apis/settings/v1alpha1"
clientgotesting "k8s.io/client-go/testing"
)

Expand Down Expand Up @@ -713,115 +712,6 @@ func TestReconcileBindingDelete(t *testing.T) {
}
}

const testPodPresetName = "test-pod-preset"

func TestReconcileBindingWithPodPresetTemplate(t *testing.T) {
fakeKubeClient, fakeCatalogClient, fakeBrokerClient, testController, sharedInformers := newTestController(t, fakeosb.FakeClientConfiguration{
BindReaction: &fakeosb.BindReaction{
Response: &osb.BindResponse{
Credentials: map[string]interface{}{
"a": "b",
"c": "d",
},
},
},
})

addGetNamespaceReaction(fakeKubeClient)
addGetSecretNotFoundReaction(fakeKubeClient)

fakeKubeClient.AddReactor("create", "podpresets", func(action clientgotesting.Action) (bool, runtime.Object, error) {
return true, nil, nil
})

sharedInformers.Brokers().Informer().GetStore().Add(getTestBroker())
sharedInformers.ServiceClasses().Informer().GetStore().Add(getTestServiceClass())
sharedInformers.Instances().Informer().GetStore().Add(getTestInstanceWithStatus(v1alpha1.ConditionTrue))

binding := &v1alpha1.Binding{
ObjectMeta: metav1.ObjectMeta{Name: testBindingName, Namespace: testNamespace},
Spec: v1alpha1.BindingSpec{
InstanceRef: v1.LocalObjectReference{Name: testInstanceName},
ExternalID: bindingGUID,
SecretName: testBindingSecretName,
AlphaPodPresetTemplate: &v1alpha1.AlphaPodPresetTemplate{
Name: testPodPresetName,
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
"foo": "bar",
},
},
},
},
}

err := testController.reconcileBinding(binding)
if err != nil {
t.Fatalf("%v", err)
}

brokerActions := fakeBrokerClient.Actions()
assertNumberOfBrokerActions(t, brokerActions, 1)
assertBind(t, brokerActions[0], &osb.BindRequest{
BindingID: bindingGUID,
InstanceID: instanceGUID,
ServiceID: serviceClassGUID,
PlanID: planGUID,
AppGUID: strPtr(testNsUID),
BindResource: &osb.BindResource{
AppGUID: strPtr(testNsUID),
},
})

actions := fakeCatalogClient.Actions()
assertNumberOfActions(t, actions, 1)

// There should only be one action that says binding was created
updatedBinding := assertUpdateStatus(t, actions[0], binding)
assertBindingReadyTrue(t, updatedBinding)

kubeActions := fakeKubeClient.Actions()
assertNumberOfActions(t, kubeActions, 4)

action := kubeActions[2].(clientgotesting.CreateAction)
if e, a := "create", action.GetVerb(); e != a {
t.Fatalf("Unexpected verb on action; expected %v, got %v", e, a)
}
if e, a := "secrets", action.GetResource().Resource; e != a {
t.Fatalf("Unexpected resource on action; expected %v, got %v", e, a)
}
actionSecret, ok := action.GetObject().(*v1.Secret)
if !ok {
t.Fatal("couldn't convert secret into a v1.Secret")
}
if e, a := testBindingSecretName, actionSecret.Name; e != a {
t.Fatalf("Unexpected name of secret; expected %v, got %v", e, a)
}

action = kubeActions[3].(clientgotesting.CreateAction)
if e, a := "create", action.GetVerb(); e != a {
t.Fatalf("Unexpected verb on action; expected %v, got %v", e, a)
}
if e, a := "podpresets", action.GetResource().Resource; e != a {
t.Fatalf("Unexpected resource on action; expected %v, got %v", e, a)
}
actionPodPreset, ok := action.GetObject().(*settingsv1alpha1.PodPreset)
if !ok {
t.Fatal("couldn't convert PodPreset into a settingsv1alpha1.PodPreset")
}
if e, a := testPodPresetName, actionPodPreset.Name; e != a {
t.Fatalf("Unexpected name of PodPreset; expected %v, got %v", e, a)
}

events := getRecordedEvents(testController)
assertNumEvents(t, events, 1)

expectedEvent := api.EventTypeNormal + " " + successInjectedBindResultReason + " " + successInjectedBindResultMessage
if e, a := expectedEvent, events[0]; e != a {
t.Fatalf("Received unexpected event: %v", a)
}
}

func TestReconcileBindingWithBrokerError(t *testing.T) {
_, _, _, testController, sharedInformers := newTestController(t, fakeosb.FakeClientConfiguration{
BindReaction: &fakeosb.BindReaction{
Expand Down

0 comments on commit 8887561

Please sign in to comment.