Skip to content

Commit

Permalink
Adds ability to filter by [Cluster]ServicePlan.spec.free
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyrickard committed Jul 18, 2018
1 parent 2e6408d commit df87f52
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions pkg/apis/servicecatalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ type CommonServiceBrokerSpec struct {
// name - the value set to [Cluster]ServicePlan.Name
// spec.externalName - the value set to [Cluster]ServicePlan.Spec.ExternalName
// spec.externalID - the value set to [Cluster]ServicePlan.Spec.ExternalID
// spec.free - the value set to [Cluster]ServicePlan.Spec.Free
// spec.serviceClassName - the value set to ServicePlan.Spec.ServiceClassRef.Name
// spec.clusterServiceClass.name - the value set to ClusterServicePlan.Spec.ClusterServiceClassRef.Name
type CatalogRestrictions struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/servicecatalog/v1beta1/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1beta1

import (
"strconv"

"github.com/kubernetes-incubator/service-catalog/pkg/filter"
"k8s.io/apimachinery/pkg/labels"
)
Expand Down Expand Up @@ -50,6 +52,7 @@ func ConvertServicePlanToProperties(servicePlan *ServicePlan) filter.Properties
FilterSpecExternalName: servicePlan.Spec.ExternalName,
FilterSpecExternalID: servicePlan.Spec.ExternalID,
FilterSpecServiceClassName: servicePlan.Spec.ServiceClassRef.Name,
FilterSpecFree: strconv.FormatBool(servicePlan.Spec.Free),
}
}

Expand Down Expand Up @@ -79,5 +82,6 @@ func ConvertClusterServicePlanToProperties(servicePlan *ClusterServicePlan) filt
FilterSpecExternalName: servicePlan.Spec.ExternalName,
FilterSpecExternalID: servicePlan.Spec.ExternalID,
FilterSpecClusterServiceClassName: servicePlan.Spec.ClusterServiceClassRef.Name,
FilterSpecFree: strconv.FormatBool(servicePlan.Spec.Free),
}
}
6 changes: 4 additions & 2 deletions pkg/apis/servicecatalog/v1beta1/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ func TestConvertServicePlanToProperties(t *testing.T) {
CommonServicePlanSpec: CommonServicePlanSpec{
ExternalName: "external-plan-name",
ExternalID: "external-id",
Free: true,
},
ServiceClassRef: LocalObjectReference{
Name: "service-class-name",
},
},
},
json: `{"name":"service-plan","spec.externalID":"external-id","spec.externalName":"external-plan-name","spec.serviceClass.name":"service-class-name"}`,
json: `{"name":"service-plan","spec.externalID":"external-id","spec.externalName":"external-plan-name","spec.free":"true","spec.serviceClass.name":"service-class-name"}`,
},
}
for _, tc := range cases {
Expand Down Expand Up @@ -170,13 +171,14 @@ func TestConvertClusterServicePlanToProperties(t *testing.T) {
CommonServicePlanSpec: CommonServicePlanSpec{
ExternalName: "external-plan-name",
ExternalID: "external-id",
Free: true,
},
ClusterServiceClassRef: ClusterObjectReference{
Name: "cluster-service-class-name",
},
},
},
json: `{"name":"service-plan","spec.clusterServiceClass.name":"cluster-service-class-name","spec.externalID":"external-id","spec.externalName":"external-plan-name"}`,
json: `{"name":"service-plan","spec.clusterServiceClass.name":"cluster-service-class-name","spec.externalID":"external-id","spec.externalName":"external-plan-name","spec.free":"true"}`,
},
}
for _, tc := range cases {
Expand Down
11 changes: 7 additions & 4 deletions pkg/apis/servicecatalog/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,21 @@ type CommonServiceBrokerSpec struct {
// This is an example of a whitelist on service externalName.
// Goal: Only list Services with the externalName of FooService and BarService,
// Solution: restrictions := ServiceCatalogRestrictions{
// ServiceClass: ["externalName in (FooService, BarService)"]
// ServiceClass: ["spec.externalName in (FooService, BarService)"]
// }
//
// This is an example of a blacklist on service externalName.
// Goal: Allow all services except the ones with the externalName of FooService and BarService,
// Solution: restrictions := ServiceCatalogRestrictions{
// ServiceClass: ["externalName notin (FooService, BarService)"]
// ServiceClass: ["spec.externalName notin (FooService, BarService)"]
// }
//
// This whitelists plans called "Demo", and blacklists (but only a single element in
// the list) a service and a plan.
// Goal: Allow all plans with the externalName demo, but not AABBCC, and not a specific service by name,
// Solution: restrictions := ServiceCatalogRestrictions{
// ServiceClass: ["name!=AABBB-CCDD-EEGG-HIJK"]
// ServicePlan: ["externalName in (Demo)", "name!=AABBCC"]
// ServicePlan: ["spec.externalName in (Demo)", "name!=AABBCC"]
// }
//
// CatalogRestrictions strings have a special format similar to Label Selectors,
Expand All @@ -171,8 +171,9 @@ type CommonServiceBrokerSpec struct {
// name - the value set to [Cluster]ServicePlan.Name
// spec.externalName - the value set to [Cluster]ServicePlan.Spec.ExternalName
// spec.externalID - the value set to [Cluster]ServicePlan.Spec.ExternalID
// spec.free - the value set to [Cluster]ServicePlan.Spec.Free
// spec.serviceClass.name - the value set to ServicePlan.Spec.ServiceClassRef.Name
// spec.clusterServiceClass.name - the vlaue set to ClusterServicePlan.Spec.ClusterServiceClassRef.Name
// spec.clusterServiceClass.name - the value set to ClusterServicePlan.Spec.ClusterServiceClassRef.Name
type CatalogRestrictions struct {
// ServiceClass represents a selector for plans, used to filter catalog re-lists.
ServiceClass []string `json:"serviceClass,omitempty"`
Expand Down Expand Up @@ -1372,6 +1373,8 @@ const (
FilterSpecClusterServiceClassName = "spec.clusterServiceClass.name"
// SpecServiceClassName is only used for plans, the parent service class name.
FilterSpecServiceClassName = "spec.serviceClass.name"
// FilterSpecFree is only used for plans, determines if the plan is free.
FilterSpecFree = "spec.free"
)

// SecretTransform is a single transformation that is applied to the
Expand Down
9 changes: 9 additions & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,15 @@ func TestConvertAndFilterCatalog(t *testing.T) {
plans: []string{"Goldengrove", "Queensgate"},
catalog: largeTestCatalog,
},
{
name: "filter free plans",
restrictions: &v1beta1.CatalogRestrictions{
ServicePlan: []string{"spec.free==true"},
},
classes: []string{"Arrax", "Balerion"},
plans: []string{"Eastwatch-by-the-Sea", "OldOak", "Queensgate"},
catalog: largeTestCatalog,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/openapi/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit df87f52

Please sign in to comment.