本文整理汇总了Golang中k8s/io/kubernetes/pkg/util.NewStringSet函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStringSet函数的具体用法?Golang NewStringSet怎么用?Golang NewStringSet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewStringSet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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())
}
}
示例2: 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)),
},
}
}
示例3: 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
}
示例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"),
},
},
},
},
}}
}
示例5: 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
}
示例6: TestWaitFlagNew
func TestWaitFlagNew(t *testing.T) {
fcmd := exec.FakeCmd{
CombinedOutputScript: []exec.FakeCombinedOutputAction{
// iptables version check
func() ([]byte, error) { return []byte("iptables v1.4.22"), nil },
// Success.
func() ([]byte, error) { return []byte{}, nil },
},
}
fexec := exec.FakeExec{
CommandScript: []exec.FakeCommandAction{
func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
},
}
runner := New(&fexec, ProtocolIpv4)
err := runner.DeleteChain(TableNAT, Chain("FOOBAR"))
if err != nil {
t.Errorf("expected success, got %v", err)
}
if fcmd.CombinedOutputCalls != 2 {
t.Errorf("expected 2 CombinedOutput() calls, got %d", fcmd.CombinedOutputCalls)
}
if !util.NewStringSet(fcmd.CombinedOutputLog[1]...).HasAll("iptables", "-w2") {
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[1])
}
if util.NewStringSet(fcmd.CombinedOutputLog[1]...).HasAny("-w") {
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[1])
}
}
示例7: 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}
}
示例8: 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)
}
}
}
示例9: 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())
}
}
}
}
示例10: buildClientDiagnostics
// buildClientDiagnostics builds client Diagnostic objects based on the rawConfig passed in.
// Returns the Diagnostics built, "ok" bool for whether to proceed or abort, and an error if any was encountered during the building of diagnostics.) {
func (o DiagnosticsOptions) buildClientDiagnostics(rawConfig *clientcmdapi.Config) ([]types.Diagnostic, bool, error) {
available := availableClientDiagnostics
// osClient, kubeClient, clientErr := o.Factory.Clients() // use with a diagnostic that needs OpenShift/Kube client
_, _, clientErr := o.Factory.Clients()
if clientErr != nil {
o.Logger.Notice("CED0001", "Failed creating client from config; client diagnostics will be limited to config testing")
available = util.NewStringSet(clientdiags.ConfigContextsName)
}
diagnostics := []types.Diagnostic{}
requestedDiagnostics := intersection(util.NewStringSet(o.RequestedDiagnostics...), available).List()
for _, diagnosticName := range requestedDiagnostics {
switch diagnosticName {
case clientdiags.ConfigContextsName:
for contextName := range rawConfig.Contexts {
diagnostics = append(diagnostics, clientdiags.ConfigContext{rawConfig, contextName})
}
default:
return nil, false, fmt.Errorf("unknown diagnostic: %v", diagnosticName)
}
}
return diagnostics, true, clientErr
}
示例11: 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())
}
}
示例12: TestNamespaceScopingFromEmpty
func TestNamespaceScopingFromEmpty(t *testing.T) {
router := newTestRouter(make(map[string]ServiceUnit))
templatePlugin := newDefaultTemplatePlugin(router)
// TODO: move tests that rely on unique hosts to pkg/router/controller and remove them from
// here
plugin := controller.NewUniqueHost(templatePlugin, controller.HostForRoute)
// no namespaces allowed
plugin.HandleNamespaces(util.StringSet{})
//add
route := &routeapi.Route{
ObjectMeta: kapi.ObjectMeta{Namespace: "foo", Name: "test"},
Spec: routeapi.RouteSpec{
Host: "www.example.com",
To: kapi.ObjectReference{
Name: "TestService",
},
},
}
// ignores all events for namespace that doesn't match
for _, s := range []watch.EventType{watch.Added, watch.Modified, watch.Deleted} {
plugin.HandleRoute(s, route)
if _, ok := router.FindServiceUnit("foo/TestService"); ok || plugin.HostLen() != 0 {
t.Errorf("unexpected router state %#v", router)
}
}
// allow non matching
plugin.HandleNamespaces(util.NewStringSet("bar"))
for _, s := range []watch.EventType{watch.Added, watch.Modified, watch.Deleted} {
plugin.HandleRoute(s, route)
if _, ok := router.FindServiceUnit("foo/TestService"); ok || plugin.HostLen() != 0 {
t.Errorf("unexpected router state %#v", router)
}
}
// allow foo
plugin.HandleNamespaces(util.NewStringSet("foo", "bar"))
plugin.HandleRoute(watch.Added, route)
if _, ok := router.FindServiceUnit("foo/TestService"); !ok || plugin.HostLen() != 1 {
t.Errorf("unexpected router state %#v", router)
}
// forbid foo, and make sure it's cleared
plugin.HandleNamespaces(util.NewStringSet("bar"))
if _, ok := router.FindServiceUnit("foo/TestService"); ok || plugin.HostLen() != 0 {
t.Errorf("unexpected router state %#v", router)
}
plugin.HandleRoute(watch.Modified, route)
if _, ok := router.FindServiceUnit("foo/TestService"); ok || plugin.HostLen() != 0 {
t.Errorf("unexpected router state %#v", router)
}
plugin.HandleRoute(watch.Added, route)
if _, ok := router.FindServiceUnit("foo/TestService"); ok || plugin.HostLen() != 0 {
t.Errorf("unexpected router state %#v", router)
}
}
示例13: 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()
}
示例14: 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
}
示例15: 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
}