本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/util.StringSet.List方法的典型用法代碼示例。如果您正苦於以下問題:Golang StringSet.List方法的具體用法?Golang StringSet.List怎麽用?Golang StringSet.List使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/GoogleCloudPlatform/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: 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)
}
}
示例3: 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
}
示例4: 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
}
示例5: printPolicy
func printPolicy(policy *authorizationapi.Policy, w io.Writer, withNamespace bool) error {
roleNames := util.StringSet{}
for key := range policy.Roles {
roleNames.Insert(key)
}
rolesString := strings.Join(roleNames.List(), ", ")
_, err := fmt.Fprintf(w, "%s\t%s\t%v\n", policy.Name, rolesString, policy.LastModified)
return err
}
示例6: 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
}
示例7: printDeployment
func printDeployment(d *api.Deployment, w io.Writer) error {
causes := util.StringSet{}
if d.Details != nil {
for _, cause := range d.Details.Causes {
causes.Insert(string(cause.Type))
}
}
cStr := strings.Join(causes.List(), ", ")
_, err := fmt.Fprintf(w, "%s\t%s\t%s\n", d.Name, d.Status, cStr)
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{}
buildStatusOptions := []buildapi.BuildStatus{
buildapi.BuildStatusCancelled,
buildapi.BuildStatusComplete,
buildapi.BuildStatusError,
buildapi.BuildStatusFailed,
buildapi.BuildStatusNew,
buildapi.BuildStatusPending,
buildapi.BuildStatusRunning,
}
buildStatusFilter := []buildapi.BuildStatus{
buildapi.BuildStatusCancelled,
buildapi.BuildStatusComplete,
buildapi.BuildStatusError,
buildapi.BuildStatusFailed,
}
buildStatusFilterSet := util.StringSet{}
for _, buildStatus := range buildStatusFilter {
buildStatusFilterSet.Insert(string(buildStatus))
}
for _, buildStatusOption := range buildStatusOptions {
builds = append(builds, withStatus(mockBuild("a", string(buildStatusOption)+"-active", activeBuildConfig), buildStatusOption))
builds = append(builds, withStatus(mockBuild("a", string(buildStatusOption)+"-inactive", inactiveBuildConfig), buildStatusOption))
builds = append(builds, withStatus(mockBuild("a", string(buildStatusOption)+"-orphan", nil), buildStatusOption))
if buildStatusFilterSet.Has(string(buildStatusOption)) {
expectedNames.Insert(string(buildStatusOption) + "-inactive")
expectedNames.Insert(string(buildStatusOption) + "-orphan")
}
}
dataSet := NewDataSet(buildConfigs, builds)
resolver := NewOrphanBuildResolver(dataSet, buildStatusFilter)
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: getPriorityFunctionConfigs
func getPriorityFunctionConfigs(names util.StringSet) ([]algorithm.PriorityConfig, error) {
schedulerFactoryMutex.Lock()
defer schedulerFactoryMutex.Unlock()
configs := []algorithm.PriorityConfig{}
for _, name := range names.List() {
config, ok := priorityFunctionMap[name]
if !ok {
return nil, fmt.Errorf("Invalid priority name %s specified - no corresponding function found", name)
}
configs = append(configs, config)
}
return configs, nil
}
示例11: getFitPredicateFunctions
func getFitPredicateFunctions(names util.StringSet) ([]algorithm.FitPredicate, error) {
schedulerFactoryMutex.Lock()
defer schedulerFactoryMutex.Unlock()
predicates := []algorithm.FitPredicate{}
for _, name := range names.List() {
function, ok := fitPredicateMap[name]
if !ok {
return nil, fmt.Errorf("Invalid predicate name %q specified - no corresponding function found", name)
}
predicates = append(predicates, function)
}
return predicates, nil
}
示例12: 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
}
示例13: 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)
}
}
示例14: 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
}
示例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)
}