Skip to content

Commit

Permalink
Adding ServicePlan (namespaced plans) API
Browse files Browse the repository at this point in the history
This PR introduces the new ServicePlan type, along with supporting
changes to expose in the API.

Part of kubernetes-retired#1200
  • Loading branch information
jeremyrickard committed Mar 30, 2018
1 parent 2da1e43 commit 4196047
Show file tree
Hide file tree
Showing 20 changed files with 1,457 additions and 31 deletions.
2 changes: 1 addition & 1 deletion contrib/examples/apiserver/clusterserviceplan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: 10e03cb7-b2cf-40dd-a954-16a382b92446
spec:
clusterServiceBrokerName: test-broker
externalName: test-serviceplan
externalName: test-clusterserviceplan
externalID: 10e03cb7-b2cf-40dd-a954-16a382b92446
description: "plan description"
free: true
Expand Down
12 changes: 12 additions & 0 deletions contrib/examples/apiserver/serviceplan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: servicecatalog.k8s.io/v1beta1
kind: ServicePlan
metadata:
name: b20ac1c6-f6d5-4dd0-b30c-c33242ad2083
spec:
serviceBrokerName: test-ns-broker
externalName: test-serviceplan
externalID: b20ac1c6-f6d5-4dd0-b30c-c33242ad2083
description: "plan description"
free: true
serviceClassRef:
name: d0fe444d-5656-4c7a-ba1b-6c5884eefbb7
3 changes: 3 additions & 0 deletions contrib/hack/test-apiserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ NO_TTY=1 kubectl create -f contrib/examples/apiserver/broker.yaml
NO_TTY=1 kubectl create -f contrib/examples/apiserver/clusterserviceclass.yaml
NO_TTY=1 kubectl create -f contrib/examples/apiserver/serviceclass.yaml
NO_TTY=1 kubectl create -f contrib/examples/apiserver/clusterserviceplan.yaml
NO_TTY=1 kubectl create -f contrib/examples/apiserver/serviceplan.yaml
NO_TTY=1 kubectl create -f contrib/examples/apiserver/instance.yaml
NO_TTY=1 kubectl create -f contrib/examples/apiserver/binding.yaml
NO_TTY=1 kubectl create -f contrib/examples/apiserver/podpreset.yaml
Expand All @@ -54,6 +55,7 @@ NO_TTY=1 kubectl get clusterservicebroker test-broker -o yaml
NO_TTY=1 kubectl get clusterserviceclass d35b55b2-b1fd-4123-8045-5b9c619cb629 -o yaml
NO_TTY=1 kubectl get serviceclass d0fe444d-5656-4c7a-ba1b-6c5884eefbb7 --namespace test-ns -o yaml
NO_TTY=1 kubectl get clusterserviceplan 10e03cb7-b2cf-40dd-a954-16a382b92446 -o yaml
NO_TTY=1 kubectl get serviceplan b20ac1c6-f6d5-4dd0-b30c-c33242ad2083 --namespace test-ns -o yaml
NO_TTY=1 kubectl get serviceinstance test-instance --namespace test-ns -o yaml
NO_TTY=1 kubectl get servicebinding test-binding --namespace test-ns -o yaml
NO_TTY=1 kubectl get podpresets -o yaml
Expand All @@ -63,6 +65,7 @@ NO_TTY=1 kubectl delete -f contrib/examples/apiserver/broker.yaml
NO_TTY=1 kubectl delete -f contrib/examples/apiserver/clusterserviceclass.yaml
NO_TTY=1 kubectl delete -f contrib/examples/apiserver/serviceclass.yaml
NO_TTY=1 kubectl delete -f contrib/examples/apiserver/clusterserviceplan.yaml
NO_TTY=1 kubectl delete -f contrib/examples/apiserver/serviceplan.yaml
NO_TTY=1 kubectl delete -f contrib/examples/apiserver/instance.yaml
NO_TTY=1 kubectl delete -f contrib/examples/apiserver/binding.yaml
NO_TTY=1 kubectl delete -f contrib/examples/apiserver/podpreset.yaml
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/servicecatalog/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&ServiceClassList{},
&ClusterServicePlan{},
&ClusterServicePlanList{},
&ServicePlan{},
&ServicePlanList{},
&ServiceInstance{},
&ServiceInstanceList{},
&ServiceBinding{},
Expand Down
14 changes: 13 additions & 1 deletion pkg/apis/servicecatalog/testing/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,19 @@ func servicecatalogFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
}
sc.Spec.ExternalMetadata = metadata
},
func(sp *servicecatalog.ClusterServicePlan, c fuzz.Continue) {
func(csp *servicecatalog.ClusterServicePlan, c fuzz.Continue) {
c.FuzzNoCustom(csp)
metadata, err := createPlanMetadata(c)
if err != nil {
panic(fmt.Sprintf("Failed to create metadata object: %v", err))
}
csp.Spec.ExternalMetadata = metadata
csp.Spec.ServiceBindingCreateResponseSchema = metadata
csp.Spec.ServiceBindingCreateParameterSchema = metadata
csp.Spec.ServiceInstanceCreateParameterSchema = metadata
csp.Spec.ServiceInstanceUpdateParameterSchema = metadata
},
func(sp *servicecatalog.ServicePlan, c fuzz.Continue) {
c.FuzzNoCustom(sp)
metadata, err := createPlanMetadata(c)
if err != nil {
Expand Down
50 changes: 49 additions & 1 deletion pkg/apis/servicecatalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ type ServiceClassSpec struct {

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ClusterServicePlanList is a list of ServicePlans.
// ClusterServicePlanList is a list of ClusterServicePlans.
type ClusterServicePlanList struct {
metav1.TypeMeta
metav1.ListMeta
Expand Down Expand Up @@ -457,13 +457,61 @@ type ClusterServicePlanSpec struct {
// ClusterServicePlanStatus represents status information about a
// ClusterServicePlan.
type ClusterServicePlanStatus struct {
CommonServicePlanStatus
}

// CommonServicePlanStatus represents status information about a
// ClusterServicePlan or a ServicePlan.
type CommonServicePlanStatus struct {
// RemovedFromBrokerCatalog indicates that the broker removed the plan
// from its catalog.
RemovedFromBrokerCatalog bool
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ServicePlanList is a list of ServicePlans.
type ServicePlanList struct {
metav1.TypeMeta
metav1.ListMeta

Items []ServicePlan
}

// +genclient

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ServicePlan represents a tier of a ServiceClass.
type ServicePlan struct {
metav1.TypeMeta
metav1.ObjectMeta

Spec ServicePlanSpec
Status ServicePlanStatus
}

// ServicePlanSpec represents details about the ServicePlan
type ServicePlanSpec struct {
CommonServicePlanSpec

// ServiceBrokerName is the name of the ServiceBroker that offers this
// ServicePlan.
ServiceBrokerName string

// ServiceClassRef is a reference to the service class that
// owns this plan.
ServiceClassRef LocalObjectReference
}

// ServicePlanStatus represents status information about a
// ServicePlan.
type ServicePlanStatus struct {
CommonServicePlanStatus
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ServiceInstanceList is a list of instances.
type ServiceInstanceList struct {
metav1.TypeMeta
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/servicecatalog/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ func ClusterServicePlanFieldLabelConversionFunc(label, value string) (string, st
}
}

// ServicePlanFieldLabelConversionFunc does not convert anything, just returns
// what it's given for the supported fields, and errors for unsupported.
func ServicePlanFieldLabelConversionFunc(label, value string) (string, string, error) {
switch label {
case "spec.externalID",
"spec.externalName",
"spec.serviceBrokerName",
"spec.serviceClassRef.name":
return label, value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
}

// ServiceClassFieldLabelConversionFunc does not convert anything, just returns
// what it's given for the supported fields, and errors for unsupported.
func ServiceClassFieldLabelConversionFunc(label, value string) (string, string, error) {
Expand Down
48 changes: 48 additions & 0 deletions pkg/apis/servicecatalog/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,54 @@ func TestClusterServicePlanFieldLabelConversionFunc(t *testing.T) {
runTestCases(t, cases, "ClusterServicePlanFieldLabelConversionFunc", ClusterServicePlanFieldLabelConversionFunc)
}

func TestServicePlanFieldLabelConversionFunc(t *testing.T) {
cases := []testcase{
{
name: "spec.externalName works",
inLabel: "spec.externalName",
inValue: "somenamehere",
outLabel: "spec.externalName",
outValue: "somenamehere",
success: true,
},
{
name: "spec.serviceClassRef.name works",
inLabel: "spec.serviceClassRef.name",
inValue: "someref",
outLabel: "spec.serviceClassRef.name",
outValue: "someref",
success: true,
},
{
name: "spec.serviceBrokerName works",
inLabel: "spec.serviceBrokerName",
inValue: "somebroker",
outLabel: "spec.serviceBrokerName",
outValue: "somebroker",
success: true,
},
{
name: "spec.externalID works",
inLabel: "spec.externalID",
inValue: "externalid",
outLabel: "spec.externalID",
outValue: "externalid",
success: true,
},
{
name: "random fails",
inLabel: "spec.random",
inValue: "randomvalue",
outLabel: "",
outValue: "",
success: false,
expectedError: "field label not supported: spec.random",
},
}

runTestCases(t, cases, "ServicePlanFieldLabelConversionFunc", ServicePlanFieldLabelConversionFunc)
}

func TestClusterServiceClassFieldLabelConversionFunc(t *testing.T) {
cases := []testcase{
{
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/servicecatalog/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&ServiceClassList{},
&ClusterServicePlan{},
&ClusterServicePlanList{},
&ServicePlan{},
&ServicePlanList{},
&ServiceInstance{},
&ServiceInstanceList{},
&ServiceBinding{},
Expand All @@ -68,6 +70,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddFieldLabelConversionFunc("servicecatalog.k8s.io/v1beta1", "ClusterServiceClass", ClusterServiceClassFieldLabelConversionFunc)
scheme.AddFieldLabelConversionFunc("servicecatalog.k8s.io/v1beta1", "ServiceClass", ServiceClassFieldLabelConversionFunc)
scheme.AddFieldLabelConversionFunc("servicecatalog.k8s.io/v1beta1", "ClusterServicePlan", ClusterServicePlanFieldLabelConversionFunc)
scheme.AddFieldLabelConversionFunc("servicecatalog.k8s.io/v1beta1", "ServicePlan", ServicePlanFieldLabelConversionFunc)
scheme.AddFieldLabelConversionFunc("servicecatalog.k8s.io/v1beta1", "ServiceInstance", ServiceInstanceFieldLabelConversionFunc)

return nil
Expand Down
61 changes: 60 additions & 1 deletion pkg/apis/servicecatalog/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ type ServiceClassSpec struct {

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ClusterServicePlanList is a list of ServicePlans.
// ClusterServicePlanList is a list of ClusterServicePlans.
type ClusterServicePlanList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down Expand Up @@ -506,13 +506,72 @@ type ClusterServicePlanSpec struct {
// ClusterServicePlanStatus represents status information about a
// ClusterServicePlan.
type ClusterServicePlanStatus struct {
CommonServicePlanStatus `json:",inline"`
}

// CommonServicePlanStatus represents status information about a
// ClusterServicePlan or a ServicePlan.
type CommonServicePlanStatus struct {
// RemovedFromBrokerCatalog indicates that the broker removed the plan
// from its catalog.
RemovedFromBrokerCatalog bool `json:"removedFromBrokerCatalog"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ServicePlanList is a list of rServicePlans.
type ServicePlanList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []ServicePlan `json:"items"`
}

// +genclient

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ServicePlan represents a tier of a ServiceClass.
// +k8s:openapi-gen=x-kubernetes-print-columns:custom-columns=NAME:.metadata.name,EXTERNAL NAME:.spec.externalName,BROKER:.spec.serviceBrokerName,CLASS:.spec.serviceClassRef.name
type ServicePlan struct {
metav1.TypeMeta `json:",inline"`

// Non-namespaced. The name of this resource in etcd is in ObjectMeta.Name.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec defines the behavior of the service plan.
// +optional
Spec ServicePlanSpec `json:"spec,omitempty"`

// Status represents the current status of the service plan.
// +optional
Status ServicePlanStatus `json:"status,omitempty"`
}

// ServicePlanSpec represents details about a ServicePlan.
type ServicePlanSpec struct {
// CommonServicePlanSpec contains the common details of this ServicePlan
CommonServicePlanSpec `json:",inline"`

// ServiceBrokerName is the name of the ServiceBroker
// that offers this ServicePlan.
ServiceBrokerName string `json:"serviceBrokerName"`

// ServiceClassRef is a reference to the service class that
// owns this plan.
ServiceClassRef LocalObjectReference `json:"serviceClassRef"`
}

// ServicePlanStatus represents status information about a
// ServicePlan.
type ServicePlanStatus struct {
CommonServicePlanStatus `json:",inline"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ServiceInstanceList is a list of instances.
type ServiceInstanceList struct {
metav1.TypeMeta `json:",inline"`
Expand Down
Loading

0 comments on commit 4196047

Please sign in to comment.