Skip to content

Commit

Permalink
Extract common service class spec fields (openshift#1834)
Browse files Browse the repository at this point in the history
* Extract shared service class spec fields

* Extract shared fields from the ClusterServiceClassSpec into a new embeddable
type: SharedServiceClassSpec

* Update generated code after rebase

* Move names from Shared* to Common*
  • Loading branch information
Erik Nelson authored and pmorie committed Mar 19, 2018
1 parent 93dab13 commit 3f8fab6
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 162 deletions.
33 changes: 19 additions & 14 deletions pkg/apis/servicecatalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,8 @@ type ClusterServiceClass struct {
Status ClusterServiceClassStatus
}

// ClusterServiceClassSpec represents details about a ClusterServicePlan
type ClusterServiceClassSpec struct {
// ClusterServiceBrokerName is the reference to the Broker that provides this
// ClusterServiceClass.
//
// Immutable.
ClusterServiceBrokerName string

// CommonServiceClassSpec represents details about a ServiceClass
type CommonServiceClassSpec struct {
// ExternalName is the name of this object that the Service Broker
// exposed this Service Class as. Mutable.
ExternalName string
Expand All @@ -249,11 +243,11 @@ type ClusterServiceClassSpec struct {
// Immutable.
ExternalID string

// Description is a short description of this ClusterServiceClass.
// Description is a short description of this ServiceClass.
Description string

// Bindable indicates whether a user can create bindings to an ServiceInstance
// provisioned from this service. ClusterServicePlan has an optional field called
// provisioned from this service. ServicePlan has an optional field called
// Bindable which overrides the value of this field.
Bindable bool

Expand All @@ -265,10 +259,10 @@ type ClusterServiceClassSpec struct {
BindingRetrievable bool

// PlanUpdatable indicates whether instances provisioned from this
// ClusterServiceClass may change ClusterServicePlans after being provisioned.
// ServiceClass may change ServicePlans after being provisioned.
PlanUpdatable bool

// ExternalMetadata is a blob of information about the ClusterServiceClass, meant
// ExternalMetadata is a blob of information about the ServiceClass, meant
// to be user-facing content and display instructions. This field may
// contain platform-specific conventional values.
ExternalMetadata *runtime.RawExtension
Expand All @@ -277,7 +271,7 @@ type ClusterServiceClassSpec struct {
// and its data will not be migrated.
//
// Tags is a list of strings that represent different classification
// attributes of the ClusterServiceClass. These are used in Cloud Foundry in a
// attributes of the ServiceClass. These are used in Cloud Foundry in a
// way similar to Kubernetes labels, but they currently have no special
// meaning in Kubernetes.
Tags []string
Expand All @@ -288,10 +282,21 @@ type ClusterServiceClassSpec struct {
// Requires exposes a list of Cloud Foundry-specific 'permissions'
// that must be granted to an instance of this service within Cloud
// Foundry. These 'permissions' have no meaning within Kubernetes and an
// ServiceInstance provisioned from this ClusterServiceClass will not work correctly.
// ServiceInstance provisioned from this ServiceClass will not work correctly.
Requires []string
}

// ClusterServiceClassSpec represents the details about a ClusterServiceClass
type ClusterServiceClassSpec struct {
CommonServiceClassSpec

// ClusterServiceBrokerName is the reference to the Broker that provides this
// ClusterServiceClass.
//
// Immutable.
ClusterServiceBrokerName string
}

// ClusterServiceClassStatus represents status information about a
// ClusterServiceClass.
type ClusterServiceClassStatus struct {
Expand Down
33 changes: 19 additions & 14 deletions pkg/apis/servicecatalog/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,8 @@ type ClusterServiceClass struct {
Status ClusterServiceClassStatus `json:"status,omitempty"`
}

// ClusterServiceClassSpec represents details about the ClusterServicePlan
type ClusterServiceClassSpec struct {
// ClusterServiceBrokerName is the reference to the Broker that provides this
// ClusterServiceClass.
//
// Immutable.
ClusterServiceBrokerName string `json:"clusterServiceBrokerName"`

// CommonServiceClassSpec represents details about a ServiceClass
type CommonServiceClassSpec struct {
// ExternalName is the name of this object that the Service Broker
// exposed this Service Class as. Mutable.
ExternalName string `json:"externalName"`
Expand All @@ -270,11 +264,11 @@ type ClusterServiceClassSpec struct {
// Immutable.
ExternalID string `json:"externalID"`

// Description is a short description of this ClusterServiceClass.
// Description is a short description of this ServiceClass.
Description string `json:"description"`

// Bindable indicates whether a user can create bindings to an
// ServiceInstance provisioned from this service. ClusterServicePlan
// ServiceInstance provisioned from this service. ServicePlan
// has an optional field called Bindable which overrides the value of
// this field.
Bindable bool `json:"bindable"`
Expand All @@ -287,12 +281,12 @@ type ClusterServiceClassSpec struct {
BindingRetrievable bool `json:"bindingRetrievable"`

// PlanUpdatable indicates whether instances provisioned from this
// ClusterServiceClass may change ClusterServicePlans after being
// ServiceClass may change ServicePlans after being
// provisioned.
PlanUpdatable bool `json:"planUpdatable"`

// ExternalMetadata is a blob of information about the
// ClusterServiceClass, meant to be user-facing content and display
// ServiceClass, meant to be user-facing content and display
// instructions. This field may contain platform-specific conventional
// values.
ExternalMetadata *runtime.RawExtension `json:"externalMetadata,omitempty"`
Expand All @@ -301,7 +295,7 @@ type ClusterServiceClassSpec struct {
// and its data will not be migrated.
//
// Tags is a list of strings that represent different classification
// attributes of the ClusterServiceClass. These are used in Cloud
// attributes of the ServiceClass. These are used in Cloud
// Foundry in a way similar to Kubernetes labels, but they currently
// have no special meaning in Kubernetes.
Tags []string `json:"tags,omitempty"`
Expand All @@ -312,11 +306,22 @@ type ClusterServiceClassSpec struct {
// Requires exposes a list of Cloud Foundry-specific 'permissions'
// that must be granted to an instance of this service within Cloud
// Foundry. These 'permissions' have no meaning within Kubernetes and an
// ServiceInstance provisioned from this ClusterServiceClass will not
// ServiceInstance provisioned from this ServiceClass will not
// work correctly.
Requires []string `json:"requires,omitempty"`
}

// ClusterServiceClassSpec represents the details about a ClusterServiceClass
type ClusterServiceClassSpec struct {
CommonServiceClassSpec `json:",inline"`

// ClusterServiceBrokerName is the reference to the Broker that provides this
// ClusterServiceClass.
//
// Immutable.
ClusterServiceBrokerName string `json:"clusterServiceBrokerName"`
}

// ClusterServiceClassStatus represents status information about a
// ClusterServiceClass.
type ClusterServiceClassStatus struct {
Expand Down
62 changes: 44 additions & 18 deletions pkg/apis/servicecatalog/v1beta1/zz_generated.conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func RegisterConversions(scheme *runtime.Scheme) error {
Convert_servicecatalog_ClusterServicePlanSpec_To_v1beta1_ClusterServicePlanSpec,
Convert_v1beta1_ClusterServicePlanStatus_To_servicecatalog_ClusterServicePlanStatus,
Convert_servicecatalog_ClusterServicePlanStatus_To_v1beta1_ClusterServicePlanStatus,
Convert_v1beta1_CommonServiceClassSpec_To_servicecatalog_CommonServiceClassSpec,
Convert_servicecatalog_CommonServiceClassSpec_To_v1beta1_CommonServiceClassSpec,
Convert_v1beta1_LocalObjectReference_To_servicecatalog_LocalObjectReference,
Convert_servicecatalog_LocalObjectReference_To_v1beta1_LocalObjectReference,
Convert_v1beta1_ObjectReference_To_servicecatalog_ObjectReference,
Expand Down Expand Up @@ -338,16 +340,10 @@ func Convert_servicecatalog_ClusterServiceClassList_To_v1beta1_ClusterServiceCla
}

func autoConvert_v1beta1_ClusterServiceClassSpec_To_servicecatalog_ClusterServiceClassSpec(in *ClusterServiceClassSpec, out *servicecatalog.ClusterServiceClassSpec, s conversion.Scope) error {
if err := Convert_v1beta1_CommonServiceClassSpec_To_servicecatalog_CommonServiceClassSpec(&in.CommonServiceClassSpec, &out.CommonServiceClassSpec, s); err != nil {
return err
}
out.ClusterServiceBrokerName = in.ClusterServiceBrokerName
out.ExternalName = in.ExternalName
out.ExternalID = in.ExternalID
out.Description = in.Description
out.Bindable = in.Bindable
out.BindingRetrievable = in.BindingRetrievable
out.PlanUpdatable = in.PlanUpdatable
out.ExternalMetadata = (*runtime.RawExtension)(unsafe.Pointer(in.ExternalMetadata))
out.Tags = *(*[]string)(unsafe.Pointer(&in.Tags))
out.Requires = *(*[]string)(unsafe.Pointer(&in.Requires))
return nil
}

Expand All @@ -357,16 +353,10 @@ func Convert_v1beta1_ClusterServiceClassSpec_To_servicecatalog_ClusterServiceCla
}

func autoConvert_servicecatalog_ClusterServiceClassSpec_To_v1beta1_ClusterServiceClassSpec(in *servicecatalog.ClusterServiceClassSpec, out *ClusterServiceClassSpec, s conversion.Scope) error {
if err := Convert_servicecatalog_CommonServiceClassSpec_To_v1beta1_CommonServiceClassSpec(&in.CommonServiceClassSpec, &out.CommonServiceClassSpec, s); err != nil {
return err
}
out.ClusterServiceBrokerName = in.ClusterServiceBrokerName
out.ExternalName = in.ExternalName
out.ExternalID = in.ExternalID
out.Description = in.Description
out.Bindable = in.Bindable
out.BindingRetrievable = in.BindingRetrievable
out.PlanUpdatable = in.PlanUpdatable
out.ExternalMetadata = (*runtime.RawExtension)(unsafe.Pointer(in.ExternalMetadata))
out.Tags = *(*[]string)(unsafe.Pointer(&in.Tags))
out.Requires = *(*[]string)(unsafe.Pointer(&in.Requires))
return nil
}

Expand Down Expand Up @@ -501,6 +491,42 @@ func Convert_servicecatalog_ClusterServicePlanStatus_To_v1beta1_ClusterServicePl
return autoConvert_servicecatalog_ClusterServicePlanStatus_To_v1beta1_ClusterServicePlanStatus(in, out, s)
}

func autoConvert_v1beta1_CommonServiceClassSpec_To_servicecatalog_CommonServiceClassSpec(in *CommonServiceClassSpec, out *servicecatalog.CommonServiceClassSpec, s conversion.Scope) error {
out.ExternalName = in.ExternalName
out.ExternalID = in.ExternalID
out.Description = in.Description
out.Bindable = in.Bindable
out.BindingRetrievable = in.BindingRetrievable
out.PlanUpdatable = in.PlanUpdatable
out.ExternalMetadata = (*runtime.RawExtension)(unsafe.Pointer(in.ExternalMetadata))
out.Tags = *(*[]string)(unsafe.Pointer(&in.Tags))
out.Requires = *(*[]string)(unsafe.Pointer(&in.Requires))
return nil
}

// Convert_v1beta1_CommonServiceClassSpec_To_servicecatalog_CommonServiceClassSpec is an autogenerated conversion function.
func Convert_v1beta1_CommonServiceClassSpec_To_servicecatalog_CommonServiceClassSpec(in *CommonServiceClassSpec, out *servicecatalog.CommonServiceClassSpec, s conversion.Scope) error {
return autoConvert_v1beta1_CommonServiceClassSpec_To_servicecatalog_CommonServiceClassSpec(in, out, s)
}

func autoConvert_servicecatalog_CommonServiceClassSpec_To_v1beta1_CommonServiceClassSpec(in *servicecatalog.CommonServiceClassSpec, out *CommonServiceClassSpec, s conversion.Scope) error {
out.ExternalName = in.ExternalName
out.ExternalID = in.ExternalID
out.Description = in.Description
out.Bindable = in.Bindable
out.BindingRetrievable = in.BindingRetrievable
out.PlanUpdatable = in.PlanUpdatable
out.ExternalMetadata = (*runtime.RawExtension)(unsafe.Pointer(in.ExternalMetadata))
out.Tags = *(*[]string)(unsafe.Pointer(&in.Tags))
out.Requires = *(*[]string)(unsafe.Pointer(&in.Requires))
return nil
}

// Convert_servicecatalog_CommonServiceClassSpec_To_v1beta1_CommonServiceClassSpec is an autogenerated conversion function.
func Convert_servicecatalog_CommonServiceClassSpec_To_v1beta1_CommonServiceClassSpec(in *servicecatalog.CommonServiceClassSpec, out *CommonServiceClassSpec, s conversion.Scope) error {
return autoConvert_servicecatalog_CommonServiceClassSpec_To_v1beta1_CommonServiceClassSpec(in, out, s)
}

func autoConvert_v1beta1_LocalObjectReference_To_servicecatalog_LocalObjectReference(in *LocalObjectReference, out *servicecatalog.LocalObjectReference, s conversion.Scope) error {
out.Name = in.Name
return nil
Expand Down
55 changes: 36 additions & 19 deletions pkg/apis/servicecatalog/v1beta1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,25 +300,7 @@ func (in *ClusterServiceClassList) DeepCopyObject() runtime.Object {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterServiceClassSpec) DeepCopyInto(out *ClusterServiceClassSpec) {
*out = *in
if in.ExternalMetadata != nil {
in, out := &in.ExternalMetadata, &out.ExternalMetadata
if *in == nil {
*out = nil
} else {
*out = new(runtime.RawExtension)
(*in).DeepCopyInto(*out)
}
}
if in.Tags != nil {
in, out := &in.Tags, &out.Tags
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.Requires != nil {
in, out := &in.Requires, &out.Requires
*out = make([]string, len(*in))
copy(*out, *in)
}
in.CommonServiceClassSpec.DeepCopyInto(&out.CommonServiceClassSpec)
return
}

Expand Down Expand Up @@ -445,6 +427,41 @@ func (in *ClusterServicePlanStatus) DeepCopy() *ClusterServicePlanStatus {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CommonServiceClassSpec) DeepCopyInto(out *CommonServiceClassSpec) {
*out = *in
if in.ExternalMetadata != nil {
in, out := &in.ExternalMetadata, &out.ExternalMetadata
if *in == nil {
*out = nil
} else {
*out = new(runtime.RawExtension)
(*in).DeepCopyInto(*out)
}
}
if in.Tags != nil {
in, out := &in.Tags, &out.Tags
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.Requires != nil {
in, out := &in.Requires, &out.Requires
*out = make([]string, len(*in))
copy(*out, *in)
}
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CommonServiceClassSpec.
func (in *CommonServiceClassSpec) DeepCopy() *CommonServiceClassSpec {
if in == nil {
return nil
}
out := new(CommonServiceClassSpec)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *LocalObjectReference) DeepCopyInto(out *LocalObjectReference) {
*out = *in
Expand Down
10 changes: 6 additions & 4 deletions pkg/apis/servicecatalog/validation/serviceclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ func validClusterServiceClass() *servicecatalog.ClusterServiceClass {
Name: "test-serviceclass",
},
Spec: servicecatalog.ClusterServiceClassSpec{
Bindable: true,
CommonServiceClassSpec: servicecatalog.CommonServiceClassSpec{
Bindable: true,
ExternalName: "test-serviceclass",
ExternalID: "1234-4354a-49b",
Description: "service description",
},
ClusterServiceBrokerName: "test-broker",
ExternalName: "test-serviceclass",
ExternalID: "1234-4354a-49b",
Description: "service description",
},
}
}
Expand Down
Loading

0 comments on commit 3f8fab6

Please sign in to comment.