本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/util.NewStringSet函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStringSet函数的具体用法?Golang NewStringSet怎么用?Golang NewStringSet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewStringSet函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: syncRequest
// syncRequest takes a reviewRequest and determines if it should update the caches supplied, it is not thread-safe
func (ac *AuthorizationCache) syncRequest(request *reviewRequest, userSubjectRecordStore cache.Store, groupSubjectRecordStore cache.Store, reviewRecordStore cache.Store) error {
lastKnownValue, err := lastKnown(reviewRecordStore, request.namespace)
if err != nil {
return err
}
if skipReview(request, lastKnownValue) {
return nil
}
namespace := request.namespace
review, err := ac.reviewer.Review(namespace)
if err != nil {
return err
}
usersToRemove := util.NewStringSet()
groupsToRemove := util.NewStringSet()
if lastKnownValue != nil {
usersToRemove.Insert(lastKnownValue.users...)
usersToRemove.Delete(review.Users()...)
groupsToRemove.Insert(lastKnownValue.groups...)
groupsToRemove.Delete(review.Groups()...)
}
deleteNamespaceFromSubjects(userSubjectRecordStore, usersToRemove.List(), namespace)
deleteNamespaceFromSubjects(groupSubjectRecordStore, groupsToRemove.List(), namespace)
addSubjectsToNamespace(userSubjectRecordStore, review.Users(), namespace)
addSubjectsToNamespace(groupSubjectRecordStore, review.Groups(), namespace)
cacheReviewRecord(request, lastKnownValue, review, reviewRecordStore)
return nil
}
开发者ID:cjnygard,项目名称:origin,代码行数:34,代码来源:cache.go
示例2: TestAdd
func TestAdd(t *testing.T) {
testCases := []struct {
sel Selector
key string
operator Operator
values []string
refSelector Selector
}{
{
LabelSelector{},
"key",
InOperator,
[]string{"value"},
LabelSelector{Requirement{"key", InOperator, util.NewStringSet("value")}},
},
{
LabelSelector{Requirement{"key", InOperator, util.NewStringSet("value")}},
"key2",
EqualsOperator,
[]string{"value2"},
LabelSelector{
Requirement{"key", InOperator, util.NewStringSet("value")},
Requirement{"key2", EqualsOperator, util.NewStringSet("value2")},
},
},
}
for _, ts := range testCases {
ts.sel = ts.sel.Add(ts.key, ts.operator, ts.values)
if !reflect.DeepEqual(ts.sel, ts.refSelector) {
t.Errorf("Expected %t found %t", ts.refSelector, ts.sel)
}
}
}
开发者ID:eghobo,项目名称:kubedash,代码行数:33,代码来源:selector_test.go
示例3: TestEscalating
func TestEscalating(t *testing.T) {
escalatingResources := ExpandResources(util.NewStringSet(GroupsToResources[EscalatingResourcesGroupName]...))
nonEscalatingResources := ExpandResources(util.NewStringSet(GroupsToResources[NonEscalatingResourcesGroupName]...))
if len(nonEscalatingResources) <= len(escalatingResources) {
t.Errorf("groups look bad: escalating=%v nonescalating=%v", escalatingResources.List(), nonEscalatingResources.List())
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:7,代码来源:group_test.go
示例4: newInvalidExtensionPolicies
func newInvalidExtensionPolicies() []authorizationapi.Policy {
return []authorizationapi.Policy{
{
ObjectMeta: kapi.ObjectMeta{
Name: authorizationapi.PolicyName,
Namespace: "mallet",
},
Roles: map[string]*authorizationapi.Role{
"badExtension": {
ObjectMeta: kapi.ObjectMeta{
Name: "failure",
Namespace: "mallet",
},
Rules: []authorizationapi.PolicyRule{
{
Verbs: util.NewStringSet("watch", "list", "get"),
Resources: util.NewStringSet("buildConfigs"),
AttributeRestrictions: runtime.EmbeddedObject{&authorizationapi.Role{}},
},
{
Verbs: util.NewStringSet("update"),
Resources: util.NewStringSet("buildConfigs"),
},
},
},
},
}}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:28,代码来源:bootstrap_policy_test.go
示例5: limitSecretReferences
func (s *serviceAccount) limitSecretReferences(serviceAccount *api.ServiceAccount, pod *api.Pod) error {
// Ensure all secrets the pod references are allowed by the service account
mountableSecrets := util.NewStringSet()
for _, s := range serviceAccount.Secrets {
mountableSecrets.Insert(s.Name)
}
for _, volume := range pod.Spec.Volumes {
source := volume.VolumeSource
if source.Secret == nil {
continue
}
secretName := source.Secret.SecretName
if !mountableSecrets.Has(secretName) {
return fmt.Errorf("Volume with secret.secretName=\"%s\" is not allowed because service account %s does not reference that secret", secretName, serviceAccount.Name)
}
}
// limit pull secret references as well
pullSecrets := util.NewStringSet()
for _, s := range serviceAccount.ImagePullSecrets {
pullSecrets.Insert(s.Name)
}
for i, pullSecretRef := range pod.Spec.ImagePullSecrets {
if !pullSecrets.Has(pullSecretRef.Name) {
return fmt.Errorf(`imagePullSecrets[%d].name="%s" is not allowed because service account %s does not reference that imagePullSecret`, i, pullSecretRef.Name, serviceAccount.Name)
}
}
return nil
}
开发者ID:Ima8,项目名称:kubernetes,代码行数:29,代码来源:admission.go
示例6: newDefaultClusterPolicyBindings
func newDefaultClusterPolicyBindings() []authorizationapi.ClusterPolicyBinding {
policyBinding := authorizationapi.ClusterPolicyBinding{
ObjectMeta: kapi.ObjectMeta{
Name: authorizationapi.ClusterPolicyBindingName,
},
RoleBindings: map[string]*authorizationapi.ClusterRoleBinding{
"extra-cluster-admins": {
ObjectMeta: kapi.ObjectMeta{
Name: "cluster-admins",
},
RoleRef: kapi.ObjectReference{
Name: "cluster-admin",
},
Users: util.NewStringSet("ClusterAdmin"),
Groups: util.NewStringSet("RootUsers"),
},
"user-only": {
ObjectMeta: kapi.ObjectMeta{
Name: "user-only",
},
RoleRef: kapi.ObjectReference{
Name: "basic-user",
},
Users: util.NewStringSet("just-a-user"),
},
},
}
for key, value := range GetBootstrapPolicyBinding().RoleBindings {
policyBinding.RoleBindings[key] = value
}
return []authorizationapi.ClusterPolicyBinding{policyBinding}
}
开发者ID:cjnygard,项目名称:origin,代码行数:32,代码来源:authorizer_test.go
示例7: doTestIndex
// Test public interface
func doTestIndex(t *testing.T, indexer Indexer) {
mkObj := func(id string, val string) testStoreObject {
return testStoreObject{id: id, val: val}
}
// Test Index
expected := map[string]util.StringSet{}
expected["b"] = util.NewStringSet("a", "c")
expected["f"] = util.NewStringSet("e")
expected["h"] = util.NewStringSet("g")
indexer.Add(mkObj("a", "b"))
indexer.Add(mkObj("c", "b"))
indexer.Add(mkObj("e", "f"))
indexer.Add(mkObj("g", "h"))
{
for k, v := range expected {
found := util.StringSet{}
indexResults, err := indexer.Index("by_val", mkObj("", k))
if err != nil {
t.Errorf("Unexpected error %v", err)
}
for _, item := range indexResults {
found.Insert(item.(testStoreObject).id)
}
items := v.List()
if !found.HasAll(items...) {
t.Errorf("missing items, index %s, expected %v but found %v", k, items, found.List())
}
}
}
}
开发者ID:brorhie,项目名称:panamax-kubernetes-adapter-go,代码行数:32,代码来源:store_test.go
示例8: GetBootstrapServiceAccountProjectRoleBindings
func GetBootstrapServiceAccountProjectRoleBindings(namespace string) []authorizationapi.RoleBinding {
return []authorizationapi.RoleBinding{
{
ObjectMeta: kapi.ObjectMeta{
Name: ImagePullerRoleBindingName,
Namespace: namespace,
},
RoleRef: kapi.ObjectReference{
Name: ImagePullerRoleName,
},
Groups: util.NewStringSet(serviceaccount.MakeNamespaceGroupName(namespace)),
},
{
ObjectMeta: kapi.ObjectMeta{
Name: ImageBuilderRoleBindingName,
Namespace: namespace,
},
RoleRef: kapi.ObjectReference{
Name: ImageBuilderRoleName,
},
Users: util.NewStringSet(serviceaccount.MakeUsername(namespace, BuilderServiceAccountName)),
},
{
ObjectMeta: kapi.ObjectMeta{
Name: DeployerRoleBindingName,
Namespace: namespace,
},
RoleRef: kapi.ObjectReference{
Name: DeployerRoleName,
},
Users: util.NewStringSet(serviceaccount.MakeUsername(namespace, DeployerServiceAccountName)),
},
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:34,代码来源:project_policy.go
示例9: TestNodeConfigTLS
func TestNodeConfigTLS(t *testing.T) {
signerCert, signerKey, signerSerial := makeSignerCert(t)
defer os.Remove(signerCert)
defer os.Remove(signerKey)
defer os.Remove(signerSerial)
configDirName := executeNodeConfig([]string{"--node=my-node", "--hostnames=example.org", "--listen=https://0.0.0.0", "--certificate-authority=" + signerCert, "--node-client-certificate-authority=" + signerCert, "--signer-cert=" + signerCert, "--signer-key=" + signerKey, "--signer-serial=" + signerSerial})
defer os.Remove(configDirName)
configDir, err := os.Open(configDirName)
if err != nil {
t.Fatalf("unable to read %v", configDirName)
}
fileNameSlice, err := configDir.Readdirnames(0)
if err != nil {
t.Fatalf("unable to read %v", configDirName)
}
filenames := util.NewStringSet(fileNameSlice...)
expectedNames := util.NewStringSet("master-client.crt", "master-client.key", "server.crt", "server.key", "node-client-ca.crt", "node.kubeconfig", "node-config.yaml", "node-registration.json", "ca.crt")
if !filenames.HasAll(expectedNames.List()...) || !expectedNames.HasAll(filenames.List()...) {
t.Errorf("expected %v, got %v", expectedNames.List(), filenames.List())
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:25,代码来源:create_nodeconfig_test.go
示例10: init
func init() {
// set the non-escalating groups
GroupsToResources[OpenshiftNonEscalatingViewableGroupName] = ExpandResources(util.NewStringSet(GroupsToResources[OpenshiftAllGroupName]...)).
Difference(ExpandResources(util.NewStringSet(GroupsToResources[OpenshiftEscalatingViewableGroupName]...))).List()
GroupsToResources[KubeNonEscalatingViewableGroupName] = ExpandResources(util.NewStringSet(GroupsToResources[KubeAllGroupName]...)).
Difference(ExpandResources(util.NewStringSet(GroupsToResources[KubeEscalatingViewableGroupName]...))).List()
}
开发者ID:jstrachan,项目名称:kubernetes-model,代码行数:8,代码来源:types.go
示例11: convert_v1_ClusterRoleBinding_To_api_ClusterRoleBinding
func convert_v1_ClusterRoleBinding_To_api_ClusterRoleBinding(in *ClusterRoleBinding, out *newer.ClusterRoleBinding, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields|conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
out.Users = util.NewStringSet(in.UserNames...)
out.Groups = util.NewStringSet(in.GroupNames...)
return nil
}
开发者ID:cjnygard,项目名称:origin,代码行数:10,代码来源:conversion.go
示例12: convert_v1_ResourceAccessReviewResponse_To_api_ResourceAccessReviewResponse
func convert_v1_ResourceAccessReviewResponse_To_api_ResourceAccessReviewResponse(in *ResourceAccessReviewResponse, out *newer.ResourceAccessReviewResponse, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
out.Users = util.NewStringSet(in.UsersSlice...)
out.Groups = util.NewStringSet(in.GroupsSlice...)
return nil
}
开发者ID:cjnygard,项目名称:origin,代码行数:10,代码来源:conversion.go
示例13: TestSetSelectorParser
func TestSetSelectorParser(t *testing.T) {
setSelectorParserTests := []struct {
In string
Out SetBasedSelector
Match bool
Valid bool
}{
{"", &LabelSelector{Requirements: nil}, true, true},
{"x", &LabelSelector{Requirements: []Requirement{
getRequirement("x", Exists, nil, t),
}}, true, true},
{"foo in (abc)", &LabelSelector{Requirements: []Requirement{
getRequirement("foo", In, util.NewStringSet("abc"), t),
}}, true, true},
{"x not in (abc)", &LabelSelector{Requirements: []Requirement{
getRequirement("x", NotIn, util.NewStringSet("abc"), t),
}}, true, true},
{"x not in (abc,def)", &LabelSelector{Requirements: []Requirement{
getRequirement("x", NotIn, util.NewStringSet("abc", "def"), t),
}}, true, true},
{"x in (abc,def)", &LabelSelector{Requirements: []Requirement{
getRequirement("x", In, util.NewStringSet("abc", "def"), t),
}}, true, true},
{"x in (abc,)", &LabelSelector{Requirements: []Requirement{
getRequirement("x", In, util.NewStringSet("abc", ""), t),
}}, true, true},
{"x in ()", &LabelSelector{Requirements: []Requirement{
getRequirement("x", In, util.NewStringSet(""), t),
}}, true, true},
{"x not in (abc,,def),bar,z in (),w", &LabelSelector{Requirements: []Requirement{
getRequirement("x", NotIn, util.NewStringSet("abc", "", "def"), t),
getRequirement("bar", Exists, nil, t),
getRequirement("z", In, util.NewStringSet(""), t),
getRequirement("w", Exists, nil, t),
}}, true, true},
{"x,y in (a)", &LabelSelector{Requirements: []Requirement{
getRequirement("y", In, util.NewStringSet("a"), t),
getRequirement("x", Exists, nil, t),
}}, false, true},
{"x,,y", nil, true, false},
{",x,y", nil, true, false},
{"x, y", nil, true, false},
{"x nott in (y)", nil, true, false},
{"x not in ( )", nil, true, false},
{"x not in (, a)", nil, true, false},
{"a in (xyz),", nil, true, false},
{"a in (xyz)b not in ()", nil, true, false},
{"a ", nil, true, false},
{"a not in(", nil, true, false},
}
for _, ssp := range setSelectorParserTests {
if sel, err := Parse(ssp.In); err != nil && ssp.Valid {
t.Errorf("Parse(%s) => %v expected no error", ssp.In, err)
} else if err == nil && !ssp.Valid {
t.Errorf("Parse(%s) => %+v expected error", ssp.In, sel)
} else if ssp.Match && !reflect.DeepEqual(sel, ssp.Out) {
t.Errorf("parse output %+v doesn't match %+v, expected match", sel, ssp.Out)
}
}
}
开发者ID:TencentSA,项目名称:kubernetes-0.5,代码行数:60,代码来源:selector_test.go
示例14: TestToString
func TestToString(t *testing.T) {
var req Requirement
toStringTests := []struct {
In *LabelSelector
Out string
Valid bool
}{
{&LabelSelector{Requirements: []Requirement{
getRequirement("x", InOperator, util.NewStringSet("abc", "def"), t),
getRequirement("y", NotInOperator, util.NewStringSet("jkl"), t),
getRequirement("z", ExistsOperator, nil, t),
}}, "x in (abc,def),y notin (jkl),z", true},
{&LabelSelector{Requirements: []Requirement{
getRequirement("x", InOperator, util.NewStringSet("abc", "def"), t),
req,
}}, "x in (abc,def),", false},
{&LabelSelector{Requirements: []Requirement{
getRequirement("x", NotInOperator, util.NewStringSet("abc"), t),
getRequirement("y", InOperator, util.NewStringSet("jkl", "mno"), t),
getRequirement("z", NotInOperator, util.NewStringSet(""), t),
}}, "x notin (abc),y in (jkl,mno),z notin ()", true},
{&LabelSelector{Requirements: []Requirement{
getRequirement("x", EqualsOperator, util.NewStringSet("abc"), t),
getRequirement("y", DoubleEqualsOperator, util.NewStringSet("jkl"), t),
getRequirement("z", NotEqualsOperator, util.NewStringSet("a"), t),
}}, "x=abc,y==jkl,z!=a", true},
}
for _, ts := range toStringTests {
if out := ts.In.String(); out == "" && ts.Valid {
t.Errorf("%+v.String() => '%v' expected no error", ts.In)
} else if out != ts.Out {
t.Errorf("%+v.String() => '%v' want '%v'", ts.In, out, ts.Out)
}
}
}
开发者ID:DreadPirateShawn,项目名称:heapster,代码行数:35,代码来源:selector_test.go
示例15: TestRequirementMatches
func TestRequirementMatches(t *testing.T) {
s := Set{"x": "foo", "y": "baz"}
a := Requirement{key: "x", operator: IN, strValues: util.NewStringSet("foo")}
b := Requirement{key: "x", operator: NOT_IN, strValues: util.NewStringSet("beta")}
c := Requirement{key: "y", operator: IN, strValues: nil}
d := Requirement{key: "y", strValues: util.NewStringSet("foo")}
expectMatchRequirement(t, a, s)
expectMatchRequirement(t, b, s)
expectNoMatchRequirement(t, c, s)
expectNoMatchRequirement(t, d, s)
}
开发者ID:K-A-Z,项目名称:kubernetes,代码行数:11,代码来源:selector_test.go
示例16: Run
func (o *RemoveFromProjectOptions) Run() error {
bindingList, err := o.Client.PolicyBindings(o.BindingNamespace).List(labels.Everything(), fields.Everything())
if err != nil {
return err
}
sort.Sort(authorizationapi.PolicyBindingSorter(bindingList.Items))
usersRemoved := util.StringSet{}
groupsRemoved := util.StringSet{}
for _, currPolicyBinding := range bindingList.Items {
for _, currBinding := range authorizationapi.SortRoleBindings(currPolicyBinding.RoleBindings, true) {
bindingHasGroups := len(o.Groups) > 0 && currBinding.Groups.HasAny(o.Groups...)
bindingHasUsers := len(o.Users) > 0 && currBinding.Users.HasAny(o.Users...)
if !bindingHasGroups && !bindingHasUsers {
continue
}
existingGroups := util.NewStringSet(currBinding.Groups.List()...)
existingUsers := util.NewStringSet(currBinding.Users.List()...)
currBinding.Groups.Delete(o.Groups...)
currBinding.Users.Delete(o.Users...)
_, err = o.Client.RoleBindings(o.BindingNamespace).Update(currBinding)
if err != nil {
return err
}
roleDisplayName := fmt.Sprintf("%s/%s", currBinding.RoleRef.Namespace, currBinding.RoleRef.Name)
if len(currBinding.RoleRef.Namespace) == 0 {
roleDisplayName = currBinding.RoleRef.Name
}
if diff := existingGroups.Difference(currBinding.Groups); len(diff) != 0 {
fmt.Fprintf(o.Out, "Removing %s from groups %v in project %s.\n", roleDisplayName, diff.List(), o.BindingNamespace)
groupsRemoved.Insert(diff.List()...)
}
if diff := existingUsers.Difference(currBinding.Users); len(diff) != 0 {
fmt.Fprintf(o.Out, "Removing %s from users %v in project %s.\n", roleDisplayName, diff.List(), o.BindingNamespace)
usersRemoved.Insert(diff.List()...)
}
}
}
if diff := util.NewStringSet(o.Groups...).Difference(groupsRemoved); len(diff) != 0 {
fmt.Fprintf(o.Out, "Groups %v were not bound to roles in project %s.\n", diff.List(), o.BindingNamespace)
}
if diff := util.NewStringSet(o.Users...).Difference(usersRemoved); len(diff) != 0 {
fmt.Fprintf(o.Out, "Users %v were not bound to roles in project %s.\n", diff.List(), o.BindingNamespace)
}
return nil
}
开发者ID:nstrug,项目名称:origin,代码行数:53,代码来源:remove_from_project.go
示例17: TestResourceStarCoveringStar
func TestResourceStarCoveringStar(t *testing.T) {
escalationTest{
ownerRules: []authorizationapi.PolicyRule{
{Verbs: util.NewStringSet("get"), Resources: util.NewStringSet("*")},
},
servantRules: []authorizationapi.PolicyRule{
{Verbs: util.NewStringSet("get"), Resources: util.NewStringSet("*")},
},
expectedCovered: true,
expectedUncoveredRules: []authorizationapi.PolicyRule{},
}.test(t)
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:13,代码来源:policy_comparator_test.go
示例18: TestResourceNameEmptyCoveringMultiple
func TestResourceNameEmptyCoveringMultiple(t *testing.T) {
escalationTest{
ownerRules: []authorizationapi.PolicyRule{
{Verbs: util.NewStringSet("get"), Resources: util.NewStringSet("pods"), ResourceNames: util.NewStringSet()},
},
servantRules: []authorizationapi.PolicyRule{
{Verbs: util.NewStringSet("get"), Resources: util.NewStringSet("pods"), ResourceNames: util.NewStringSet("foo", "bar")},
},
expectedCovered: true,
expectedUncoveredRules: []authorizationapi.PolicyRule{},
}.test(t)
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:13,代码来源:policy_comparator_test.go
示例19: TestResourceGroupCoveringEnumerated
func TestResourceGroupCoveringEnumerated(t *testing.T) {
escalationTest{
ownerRules: []authorizationapi.PolicyRule{
{Verbs: util.NewStringSet("create", "delete", "update"), Resources: util.NewStringSet("resourcegroup:builds")},
},
servantRules: []authorizationapi.PolicyRule{
{Verbs: util.NewStringSet("delete", "update"), Resources: util.NewStringSet("builds", "buildconfigs")},
},
expectedCovered: true,
expectedUncoveredRules: []authorizationapi.PolicyRule{},
}.test(t)
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:13,代码来源:policy_comparator_test.go
示例20: TestEnumeratedCoveringResourceGroup
func TestEnumeratedCoveringResourceGroup(t *testing.T) {
escalationTest{
ownerRules: []authorizationapi.PolicyRule{
{Verbs: util.NewStringSet("delete", "update"), Resources: util.NewStringSet("builds", "buildconfigs", "buildlogs", "buildconfigs/instantiate", "builds/log", "builds/clone", "buildconfigs/webhooks")},
},
servantRules: []authorizationapi.PolicyRule{
{Verbs: util.NewStringSet("delete", "update"), Resources: util.NewStringSet("resourcegroup:builds")},
},
expectedCovered: true,
expectedUncoveredRules: []authorizationapi.PolicyRule{},
}.test(t)
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:13,代码来源:policy_comparator_test.go
注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/util.NewStringSet函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论