本文整理汇总了Golang中k8s/io/kubernetes/pkg/util.StringSet.List方法的典型用法代码示例。如果您正苦于以下问题:Golang StringSet.List方法的具体用法?Golang StringSet.List怎么用?Golang StringSet.List使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/util.StringSet
的用法示例。
在下文中一共展示了StringSet.List方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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())
}
}
}
}
示例2: usersWithCommit
func usersWithCommit(client *github.Client, org, project string) ([]string, error) {
userSet := util.StringSet{}
teams, err := fetchAllTeams(client, org)
if err != nil {
glog.Errorf("%v", err)
return nil, err
}
teamIDs := []int{}
for _, team := range teams {
repo, _, err := client.Organizations.IsTeamRepo(*team.ID, org, project)
if repo == nil || err != nil {
continue
}
perms := *repo.Permissions
if perms["push"] {
teamIDs = append(teamIDs, *team.ID)
}
}
for _, team := range teamIDs {
users, err := fetchAllUsers(client, team)
if err != nil {
glog.Errorf("%v", err)
continue
}
for _, user := range users {
userSet.Insert(*user.Login)
}
}
return userSet.List(), nil
}
示例3: Verify
func (m *mockPruneRecorder) Verify(t *testing.T, expected util.StringSet) {
if len(m.set) != len(expected) || !m.set.HasAll(expected.List()...) {
expectedValues := expected.List()
actualValues := m.set.List()
sort.Strings(expectedValues)
sort.Strings(actualValues)
t.Errorf("expected \n\t%v\n, actual \n\t%v\n", expectedValues, actualValues)
}
}
示例4: FindOwners
func (b *BlunderbussConfig) FindOwners(filename string) []string {
owners := util.StringSet{}
for prefix, ownersList := range b.PrefixMap {
if strings.HasPrefix(filename, prefix) {
owners.Insert(ownersList...)
}
}
return owners.List()
}
示例5: ExampleInformer
func ExampleInformer() {
// source simulates an apiserver object endpoint.
source := framework.NewFakeControllerSource()
// Let's do threadsafe output to get predictable test results.
deletionCounter := make(chan string, 1000)
// Make a controller that immediately deletes anything added to it, and
// logs anything deleted.
_, controller := framework.NewInformer(
source,
&api.Pod{},
time.Millisecond*100,
framework.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
source.Delete(obj.(runtime.Object))
},
DeleteFunc: func(obj interface{}) {
key, err := framework.DeletionHandlingMetaNamespaceKeyFunc(obj)
if err != nil {
key = "oops something went wrong with the key"
}
// Report this deletion.
deletionCounter <- key
},
},
)
// Run the controller and run it until we close stop.
stop := make(chan struct{})
defer close(stop)
go controller.Run(stop)
// Let's add a few objects to the source.
testIDs := []string{"a-hello", "b-controller", "c-framework"}
for _, name := range testIDs {
// Note that these pods are not valid-- the fake source doesn't
// call validation or anything.
source.Add(&api.Pod{ObjectMeta: api.ObjectMeta{Name: name}})
}
// Let's wait for the controller to process the things we just added.
outputSet := util.StringSet{}
for i := 0; i < len(testIDs); i++ {
outputSet.Insert(<-deletionCounter)
}
for _, key := range outputSet.List() {
fmt.Println(key)
}
// Output:
// a-hello
// b-controller
// c-framework
}
示例6: printDeploymentConfig
func printDeploymentConfig(dc *deployapi.DeploymentConfig, w io.Writer, withNamespace, wide bool, columnLabels []string) error {
triggers := util.StringSet{}
for _, trigger := range dc.Triggers {
triggers.Insert(string(trigger.Type))
}
tStr := strings.Join(triggers.List(), ", ")
_, err := fmt.Fprintf(w, "%s\t%s\t%v\n", dc.Name, tStr, dc.LatestVersion)
return err
}
示例7: printPolicyBinding
func printPolicyBinding(policyBinding *authorizationapi.PolicyBinding, w io.Writer, withNamespace, wide bool, columnLabels []string) error {
roleBindingNames := util.StringSet{}
for key := range policyBinding.RoleBindings {
roleBindingNames.Insert(key)
}
roleBindingsString := strings.Join(roleBindingNames.List(), ", ")
_, err := fmt.Fprintf(w, "%s\t%s\t%v\n", policyBinding.Name, roleBindingsString, policyBinding.LastModified)
return err
}
示例8: TestOrphanBuildResolver
func TestOrphanBuildResolver(t *testing.T) {
activeBuildConfig := mockBuildConfig("a", "active-build-config")
inactiveBuildConfig := mockBuildConfig("a", "inactive-build-config")
buildConfigs := []*buildapi.BuildConfig{activeBuildConfig}
builds := []*buildapi.Build{}
expectedNames := util.StringSet{}
BuildPhaseOptions := []buildapi.BuildPhase{
buildapi.BuildPhaseCancelled,
buildapi.BuildPhaseComplete,
buildapi.BuildPhaseError,
buildapi.BuildPhaseFailed,
buildapi.BuildPhaseNew,
buildapi.BuildPhasePending,
buildapi.BuildPhaseRunning,
}
BuildPhaseFilter := []buildapi.BuildPhase{
buildapi.BuildPhaseCancelled,
buildapi.BuildPhaseComplete,
buildapi.BuildPhaseError,
buildapi.BuildPhaseFailed,
}
BuildPhaseFilterSet := util.StringSet{}
for _, BuildPhase := range BuildPhaseFilter {
BuildPhaseFilterSet.Insert(string(BuildPhase))
}
for _, BuildPhaseOption := range BuildPhaseOptions {
builds = append(builds, withStatus(mockBuild("a", string(BuildPhaseOption)+"-active", activeBuildConfig), BuildPhaseOption))
builds = append(builds, withStatus(mockBuild("a", string(BuildPhaseOption)+"-inactive", inactiveBuildConfig), BuildPhaseOption))
builds = append(builds, withStatus(mockBuild("a", string(BuildPhaseOption)+"-orphan", nil), BuildPhaseOption))
if BuildPhaseFilterSet.Has(string(BuildPhaseOption)) {
expectedNames.Insert(string(BuildPhaseOption) + "-inactive")
expectedNames.Insert(string(BuildPhaseOption) + "-orphan")
}
}
dataSet := NewDataSet(buildConfigs, builds)
resolver := NewOrphanBuildResolver(dataSet, BuildPhaseFilter)
results, err := resolver.Resolve()
if err != nil {
t.Errorf("Unexpected error %v", err)
}
foundNames := util.StringSet{}
for _, result := range results {
foundNames.Insert(result.Name)
}
if len(foundNames) != len(expectedNames) || !expectedNames.HasAll(foundNames.List()...) {
t.Errorf("expected %v, actual %v", expectedNames, foundNames)
}
}
示例9: validateList
func validateList(t *testing.T, lister Lister, user user.Info, expectedSet util.StringSet) {
namespaceList, err := lister.List(user)
if err != nil {
t.Errorf("Unexpected error %v", err)
}
results := util.StringSet{}
for _, namespace := range namespaceList.Items {
results.Insert(namespace.Name)
}
if results.Len() != expectedSet.Len() || !results.HasAll(expectedSet.List()...) {
t.Errorf("User %v, Expected: %v, Actual: %v", user.GetName(), expectedSet, results)
}
}
示例10: getFitPredicateFunctions
func getFitPredicateFunctions(names util.StringSet, args PluginFactoryArgs) (map[string]algorithm.FitPredicate, error) {
schedulerFactoryMutex.Lock()
defer schedulerFactoryMutex.Unlock()
predicates := map[string]algorithm.FitPredicate{}
for _, name := range names.List() {
factory, ok := fitPredicateMap[name]
if !ok {
return nil, fmt.Errorf("Invalid predicate name %q specified - no corresponding function found", name)
}
predicates[name] = factory(args)
}
return predicates, nil
}
示例11: TestOrphanDeploymentResolver
func TestOrphanDeploymentResolver(t *testing.T) {
activeDeploymentConfig := mockDeploymentConfig("a", "active-deployment-config")
inactiveDeploymentConfig := mockDeploymentConfig("a", "inactive-deployment-config")
deploymentConfigs := []*deployapi.DeploymentConfig{activeDeploymentConfig}
deployments := []*kapi.ReplicationController{}
expectedNames := util.StringSet{}
deploymentStatusOptions := []deployapi.DeploymentStatus{
deployapi.DeploymentStatusComplete,
deployapi.DeploymentStatusFailed,
deployapi.DeploymentStatusNew,
deployapi.DeploymentStatusPending,
deployapi.DeploymentStatusRunning,
}
deploymentStatusFilter := []deployapi.DeploymentStatus{
deployapi.DeploymentStatusComplete,
deployapi.DeploymentStatusFailed,
}
deploymentStatusFilterSet := util.StringSet{}
for _, deploymentStatus := range deploymentStatusFilter {
deploymentStatusFilterSet.Insert(string(deploymentStatus))
}
for _, deploymentStatusOption := range deploymentStatusOptions {
deployments = append(deployments, withStatus(mockDeployment("a", string(deploymentStatusOption)+"-active", activeDeploymentConfig), deploymentStatusOption))
deployments = append(deployments, withStatus(mockDeployment("a", string(deploymentStatusOption)+"-inactive", inactiveDeploymentConfig), deploymentStatusOption))
deployments = append(deployments, withStatus(mockDeployment("a", string(deploymentStatusOption)+"-orphan", nil), deploymentStatusOption))
if deploymentStatusFilterSet.Has(string(deploymentStatusOption)) {
expectedNames.Insert(string(deploymentStatusOption) + "-inactive")
expectedNames.Insert(string(deploymentStatusOption) + "-orphan")
}
}
dataSet := NewDataSet(deploymentConfigs, deployments)
resolver := NewOrphanDeploymentResolver(dataSet, deploymentStatusFilter)
results, err := resolver.Resolve()
if err != nil {
t.Errorf("Unexpected error %v", err)
}
foundNames := util.StringSet{}
for _, result := range results {
foundNames.Insert(result.Name)
}
if len(foundNames) != len(expectedNames) || !expectedNames.HasAll(foundNames.List()...) {
t.Errorf("expected %v, actual %v", expectedNames, foundNames)
}
}
示例12: MakeServerCert
func (ca *CA) MakeServerCert(certFile, keyFile string, hostnames util.StringSet) (*TLSCertificateConfig, error) {
glog.V(4).Infof("Generating server certificate in %s, key in %s", certFile, keyFile)
serverPublicKey, serverPrivateKey, _ := NewKeyPair()
serverTemplate, _ := newServerCertificateTemplate(pkix.Name{CommonName: hostnames.List()[0]}, hostnames.List())
serverCrt, _ := ca.signCertificate(serverTemplate, serverPublicKey)
server := &TLSCertificateConfig{
Certs: append([]*x509.Certificate{serverCrt}, ca.Config.Certs...),
Key: serverPrivateKey,
}
if err := server.writeCertConfig(certFile, keyFile); err != nil {
return server, err
}
return server, nil
}
示例13: printPolicy
func printPolicy(policy *authorizationapi.Policy, w io.Writer, withNamespace, wide bool, columnLabels []string) error {
roleNames := util.StringSet{}
for key := range policy.Roles {
roleNames.Insert(key)
}
rolesString := strings.Join(roleNames.List(), ", ")
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", policy.Namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\t%s\t%v\n", policy.Name, rolesString, policy.LastModified)
return err
}
示例14: getPriorityFunctionConfigs
func getPriorityFunctionConfigs(names util.StringSet, args PluginFactoryArgs) ([]algorithm.PriorityConfig, error) {
schedulerFactoryMutex.Lock()
defer schedulerFactoryMutex.Unlock()
configs := []algorithm.PriorityConfig{}
for _, name := range names.List() {
factory, ok := priorityFunctionMap[name]
if !ok {
return nil, fmt.Errorf("Invalid priority name %s specified - no corresponding function found", name)
}
configs = append(configs, algorithm.PriorityConfig{
Function: factory.Function(args),
Weight: factory.Weight,
})
}
return configs, nil
}
示例15: GetServerCert
func GetServerCert(certFile, keyFile string, hostnames util.StringSet) (*TLSCertificateConfig, error) {
server, err := GetTLSCertificateConfig(certFile, keyFile)
if err != nil {
return nil, err
}
cert := server.Certs[0]
ips, dns := IPAddressesDNSNames(hostnames.List())
missingIps := ipsNotInSlice(ips, cert.IPAddresses)
missingDns := stringsNotInSlice(dns, cert.DNSNames)
if len(missingIps) == 0 && len(missingDns) == 0 {
glog.V(4).Infof("Found existing server certificate in %s", certFile)
return server, nil
}
return nil, fmt.Errorf("Existing server certificate in %s was missing some hostnames (%v) or IP addresses (%v).", certFile, missingDns, missingIps)
}