This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 382
Add List/Relist Catalog Restrictions #1773
Merged
carolynvs
merged 53 commits into
kubernetes-retired:master
from
n3wscott:whitelist_from_labels
Apr 23, 2018
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
c0de801
Pause, going to try to use the label selector again.
4060ca1
A working example using label selectors backing code for class.
3eac4e2
Working simple example of classes and plans filtering.
c1fd237
Cleaning up the types.
9dd7bc2
Add comments for current changes.
7ecd694
Adding feature flag for Catalog Restrictions.
72f7539
A better way to filter the broker response for while/blacklists.
8cb4639
Adding documentation for how to use the label selectors.
815dba4
Adding whitespace and reordering comments to avoid confusion and delays.
4bc662a
Changing to use list, adding tests for helper.
e6c99d8
Call the catalog restriction type ServiceCatalogRestrictions
bd96336
Call the catalog restriction type ClusterServiceCatalogRestrictions
25cf545
Document the consts for filter.
6cdeb3b
document comments are strict.
48f4444
No comma. I blame Doug.
84f52a9
Revert "Pass correct plan ID in deprovision request (for both deletin…
94c89b0
Merge remote-tracking branch 'upstream/master'
4b7bc89
Merge remote-tracking branch 'upstream/master'
2e08402
Merge with master.
f959fd2
Changing types to just be lists of strings. moving some conversion to…
1590bd8
Getting Can't handle <nil> from the fuzzer.
ad38b27
just use []string
ebff045
Merge with master.
2fe49b8
Fixing up feature gate.
5785b69
Make the flag generic in the unit test.
0ce636c
Fix ConvertToSelector comment.
f0a23ad
Moving convert functions out of conversion.go.
0eb1529
make it clear we will use for list/relist.
9dcfa79
Fix comment for NewPredicate
76b5450
Fix CatalogRestrictions comment.
9039cf0
fix openapi.
5de5989
fix ConvertCluster function comments
d33b2a0
Update comment in type.
4285b72
Remove the old test no longer needed.
7144232
move filter test code to the new file location.
b6507f8
Forgot the C header.
71a7d85
copy godoc for unversioned type.
d6f8448
Reword commend from feedback.
88022e6
Open api changed after generation. update.
114dcb1
upate comments.
1b105b4
adding integration test, super simple.
ce24688
Merge branch 'master' into whitelist_from_labels
n3wscott 5e9e946
fmt'ed the features.
b7276aa
yolo, no flag.
60650e8
Rework integration test to not assume the flag.
e3aed41
Remove more cruft from the flag.
63f5691
Merge branch 'master' into whitelist_from_labels
14c39d1
godocs match 100% now.
6cbedc4
Generator generated.
0b99c5d
Merge remote-tracking branch 'upstream/master' into whitelist_from_la…
a75f8ee
ran deps ensure, got this
362278f
Merge with master.
dfdabaa
Revert sort of... back to k8s 1.10 gen.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
import ( | ||
"github.com/kubernetes-incubator/service-catalog/pkg/filter" | ||
"k8s.io/apimachinery/pkg/labels" | ||
) | ||
|
||
// These are functions to support filtering and are class specific for the ClusterServiceClass and ClusterServicePlan | ||
// This is where we can add more fields to the labels.Set to support other kinds of catalog filtering. | ||
|
||
// ConvertClusterServiceClassToProperties takes a Service Class and pulls out the | ||
// properties we support for filtering, converting them into a map in the | ||
// expected format. | ||
func ConvertClusterServiceClassToProperties(serviceClass *ClusterServiceClass) filter.Properties { | ||
if serviceClass == nil { | ||
return labels.Set{} | ||
} | ||
return labels.Set{ | ||
FilterName: serviceClass.Name, | ||
FilterSpecExternalName: serviceClass.Spec.ExternalName, | ||
FilterSpecExternalID: serviceClass.Spec.ExternalID, | ||
} | ||
} | ||
|
||
// ConvertClusterServicePlanToProperties takes a Service Plan and pulls out the | ||
// properties we support for filtering, converting them into a map in the | ||
// expected format. | ||
func ConvertClusterServicePlanToProperties(servicePlan *ClusterServicePlan) filter.Properties { | ||
if servicePlan == nil { | ||
return labels.Set{} | ||
} | ||
return labels.Set{ | ||
FilterName: servicePlan.Name, | ||
FilterSpecExternalName: servicePlan.Spec.ExternalName, | ||
FilterSpecExternalID: servicePlan.Spec.ExternalID, | ||
FilterSpecClusterServiceClassName: servicePlan.Spec.ClusterServiceClassRef.Name, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestConvertClusterServiceClassToProperties(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
sc *ClusterServiceClass | ||
json string | ||
}{ | ||
{ | ||
name: "nil object", | ||
json: "{}", | ||
}, | ||
{ | ||
name: "normal object", | ||
sc: &ClusterServiceClass{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "service-class"}, | ||
Spec: ClusterServiceClassSpec{ | ||
CommonServiceClassSpec: CommonServiceClassSpec{ | ||
ExternalName: "external-class-name", | ||
ExternalID: "external-id", | ||
}, | ||
}, | ||
}, | ||
json: `{"name":"service-class","spec.externalID":"external-id","spec.externalName":"external-class-name"}`, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
p := ConvertClusterServiceClassToProperties(tc.sc) | ||
if p == nil { | ||
t.Fatalf("Failed to create Properties object from %+v", tc.sc) | ||
} | ||
b, err := json.Marshal(p) | ||
if err != nil { | ||
t.Fatalf("Unexpected error with json marchal, %v", err) | ||
} | ||
js := string(b) | ||
if js != tc.json { | ||
t.Fatalf("Failed to create expected Properties object,\n\texpected: \t%q,\n \tgot: \t\t%q", tc.json, js) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestConvertClusterServicePlanToProperties(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
sp *ClusterServicePlan | ||
json string | ||
}{ | ||
{ | ||
name: "nil object", | ||
json: "{}", | ||
}, | ||
{ | ||
name: "normal object", | ||
sp: &ClusterServicePlan{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "service-plan"}, | ||
Spec: ClusterServicePlanSpec{ | ||
CommonServicePlanSpec: CommonServicePlanSpec{ | ||
ExternalName: "external-plan-name", | ||
ExternalID: "external-id", | ||
}, | ||
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"}`, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
p := ConvertClusterServicePlanToProperties(tc.sp) | ||
if p == nil { | ||
t.Fatalf("Failed to create Properties object from %+v", tc.sp) | ||
} | ||
b, err := json.Marshal(p) | ||
if err != nil { | ||
t.Fatalf("Unexpected error with json marchal, %v", err) | ||
} | ||
js := string(b) | ||
if js != tc.json { | ||
t.Fatalf("Failed to create expected Properties object,\n\texpected: \t%q,\n \tgot: \t\t%q", tc.json, js) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,60 @@ type CommonServiceBrokerSpec struct { | |
// can be manually incremented by a user to manually trigger a relist. | ||
// +optional | ||
RelistRequests int64 `json:"relistRequests"` | ||
|
||
// CatalogRestrictions is a set of restrictions on which of a broker's services | ||
// and plans have resources created for them. | ||
// +optional | ||
CatalogRestrictions *CatalogRestrictions `json:"catalogRestrictions,omitempty"` | ||
} | ||
|
||
// CatalogRestrictions is a set of restrictions on which of a broker's services | ||
// and plans have resources created for them. | ||
// | ||
// Some examples of this object are as follows: | ||
// | ||
// 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)"] | ||
// } | ||
// | ||
// 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)"] | ||
// } | ||
// | ||
// 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"] | ||
// } | ||
// | ||
// CatalogRestrictions strings have a special format similar to Label Selectors, | ||
// except the catalog supports only a very specific property set. | ||
// | ||
// The predicate format is expected to be `<property><conditional><requirement>` | ||
// Check the *Requirements type definition for which <property> strings will be allowed. | ||
// <conditional> is allowed to be one of the following: ==, !=, in, notin | ||
// <requirement> will be a string value if `==` or `!=` are used. | ||
// <requirement> will be a set of string values if `in` or `notin` are used. | ||
// Multiple predicates are allowed to be chained with a comma (,) | ||
// | ||
// ServiceClass allowed property names: | ||
// name - the value set to [Cluster]ServiceClass.Name | ||
// externalName - the value set to [Cluster]ServiceClass.Spec.ExternalName | ||
// | ||
// ServicePlan allowed property names: | ||
// name - the value set to [Cluster]ServiceClass.Name | ||
// externalName - the value set to [Cluster]ServiceClass.Spec.ExternalName | ||
type CatalogRestrictions struct { | ||
// ServiceClass represents a selector for plans, used to filter catalog re-lists. | ||
ServiceClass []string `json:"serviceClass,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note I removed custom typed strings because it was not adding value to the code. |
||
// ServicePlan represents a selector for classes, used to filter catalog re-lists. | ||
ServicePlan []string `json:"servicePlan,omitempty"` | ||
} | ||
|
||
// ClusterServiceBrokerSpec represents a description of a Broker. | ||
|
@@ -1250,6 +1304,18 @@ type ClusterObjectReference struct { | |
Name string `json:"name,omitempty"` | ||
} | ||
|
||
// Filter path for Properties | ||
const ( | ||
// Name field. | ||
FilterName = "name" | ||
// SpecExternalName is the external name of the object. | ||
FilterSpecExternalName = "spec.externalName" | ||
// SpecExternalID is the external id of the object. | ||
FilterSpecExternalID = "spec.externalID" | ||
// SpecClusterServiceClassName is only used for plans, the parent service class name. | ||
FilterSpecClusterServiceClassName = "spec.clusterServiceClass.name" | ||
) | ||
|
||
// SecretTransform is a single transformation that is applied to the | ||
// credentials returned from the broker before they are inserted into | ||
// the Secret associated with the ServiceBinding. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to put the same godoc as v1beta1 here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok updated. too much codez... (will push soon)