當前位置: 首頁>>代碼示例>>Golang>>正文


Golang String.Difference方法代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/util/sets.String.Difference方法的典型用法代碼示例。如果您正苦於以下問題:Golang String.Difference方法的具體用法?Golang String.Difference怎麽用?Golang String.Difference使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在k8s/io/kubernetes/pkg/util/sets.String的用法示例。


在下文中一共展示了String.Difference方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: dialFromNode

// dialFromNode executes a tcp or udp request based on protocol via kubectl exec
// in a test container running with host networking.
// - minTries is the minimum number of curl attempts required before declaring
//   success. Set to 0 if you'd like to return as soon as all endpoints respond
//   at least once.
// - maxTries is the maximum number of curl attempts. If this many attempts pass
//   and we don't see all expected endpoints, the test fails.
// maxTries == minTries will confirm that we see the expected endpoints and no
// more for maxTries. Use this if you want to eg: fail a readiness check on a
// pod and confirm it doesn't show up as an endpoint.
func (config *NetworkingTestConfig) dialFromNode(protocol, targetIP string, targetPort, maxTries, minTries int, expectedEps sets.String) {
    var cmd string
    if protocol == "udp" {
        cmd = fmt.Sprintf("echo 'hostName' | timeout -t 3 nc -w 1 -u %s %d", targetIP, targetPort)
    } else {
        cmd = fmt.Sprintf("curl -q -s --connect-timeout 1 http://%s:%d/hostName", targetIP, targetPort)
    }

    // TODO: This simply tells us that we can reach the endpoints. Check that
    // the probability of hitting a specific endpoint is roughly the same as
    // hitting any other.
    eps := sets.NewString()

    filterCmd := fmt.Sprintf("%s | grep -v '^\\s*$'", cmd)
    for i := 0; i < maxTries; i++ {
        stdout, err := framework.RunHostCmd(config.ns, config.hostTestContainerPod.Name, filterCmd)
        if err != nil {
            // A failure to kubectl exec counts as a try, not a hard fail.
            // Also note that we will keep failing for maxTries in tests where
            // we confirm unreachability.
            framework.Logf("Failed to execute %v: %v", filterCmd, err)
        } else {
            eps.Insert(strings.TrimSpace(stdout))
        }
        framework.Logf("Waiting for %+v endpoints, got endpoints %+v", expectedEps.Difference(eps), eps)

        // Check against i+1 so we exit if minTries == maxTries.
        if (eps.Equal(expectedEps) || eps.Len() == 0 && expectedEps.Len() == 0) && i+1 >= minTries {
            return
        }
    }

    config.diagnoseMissingEndpoints(eps)
    framework.Failf("Failed to find expected endpoints:\nTries %d\nCommand %v\nretrieved %v\nexpected %v\n", minTries, cmd, eps, expectedEps)
}
開發者ID:cheld,項目名稱:kubernetes,代碼行數:45,代碼來源:networking_utils.go

示例2: clusterSyncLoop

// clusterSyncLoop observes running clusters changes, and apply all services to new added cluster
// and add dns records for the changes
func (s *ServiceController) clusterSyncLoop() {
    var servicesToUpdate []*cachedService
    // should we remove cache for cluster from ready to not ready? should remove the condition predicate if no
    clusters, err := s.clusterStore.ClusterCondition(getClusterConditionPredicate()).List()
    if err != nil {
        glog.Infof("Fail to get cluster list")
        return
    }
    newClusters := clustersFromList(&clusters)
    var newSet, increase sets.String
    newSet = sets.NewString(newClusters...)
    if newSet.Equal(s.knownClusterSet) {
        // The set of cluster names in the services in the federation hasn't changed, but we can retry
        // updating any services that we failed to update last time around.
        servicesToUpdate = s.updateDNSRecords(servicesToUpdate, newClusters)
        return
    }
    glog.Infof("Detected change in list of cluster names. New  set: %v, Old set: %v", newSet, s.knownClusterSet)
    increase = newSet.Difference(s.knownClusterSet)
    // do nothing when cluster is removed.
    if increase != nil {
        // Try updating all services, and save the ones that fail to try again next
        // round.
        servicesToUpdate = s.serviceCache.allServices()
        numServices := len(servicesToUpdate)
        for newCluster := range increase {
            glog.Infof("New cluster observed %s", newCluster)
            s.updateAllServicesToCluster(servicesToUpdate, newCluster)
        }
        servicesToUpdate = s.updateDNSRecords(servicesToUpdate, newClusters)
        glog.Infof("Successfully updated %d out of %d DNS records to direct traffic to the updated cluster",
            numServices-len(servicesToUpdate), numServices)
    }
    s.knownClusterSet = newSet
}
開發者ID:cheld,項目名稱:kubernetes,代碼行數:37,代碼來源:servicecontroller.go

示例3: enforcePodContainerConstraints

// enforcePodContainerConstraints checks for required resources that are not set on this container and
// adds them to missingSet.
func enforcePodContainerConstraints(container *api.Container, requiredSet, missingSet sets.String) {
    requests := container.Resources.Requests
    limits := container.Resources.Limits
    containerUsage := podUsageHelper(requests, limits)
    containerSet := quota.ToSet(quota.ResourceNames(containerUsage))
    if !containerSet.Equal(requiredSet) {
        difference := requiredSet.Difference(containerSet)
        missingSet.Insert(difference.List()...)
    }
}
開發者ID:Q-Lee,項目名稱:kubernetes,代碼行數:12,代碼來源:pods.go

示例4: purgeDeletedNamespaces

// purgeDeletedNamespaces will remove all namespaces enumerated in a reviewRecordStore that are not in the namespace set
func (ac *AuthorizationCache) purgeDeletedNamespaces(oldNamespaces, newNamespaces sets.String, userSubjectRecordStore cache.Store, groupSubjectRecordStore cache.Store, reviewRecordStore cache.Store) {
    reviewRecordItems := reviewRecordStore.List()
    for i := range reviewRecordItems {
        reviewRecord := reviewRecordItems[i].(*reviewRecord)
        if !newNamespaces.Has(reviewRecord.namespace) {
            deleteNamespaceFromSubjects(userSubjectRecordStore, reviewRecord.users, reviewRecord.namespace)
            deleteNamespaceFromSubjects(groupSubjectRecordStore, reviewRecord.groups, reviewRecord.namespace)
            reviewRecordStore.Delete(reviewRecord)
        }
    }

    for namespace := range oldNamespaces.Difference(newNamespaces) {
        ac.notifyWatchers(namespace, nil, sets.String{}, sets.String{})
    }
}
開發者ID:sgallagher,項目名稱:origin,代碼行數:16,代碼來源:cache.go

示例5: DialFromContainer

// DialFromContainers executes a curl via kubectl exec in a test container,
// which might then translate to a tcp or udp request based on the protocol
// argument in the url.
// - minTries is the minimum number of curl attempts required before declaring
//   success. Set to 0 if you'd like to return as soon as all endpoints respond
//   at least once.
// - maxTries is the maximum number of curl attempts. If this many attempts pass
//   and we don't see all expected endpoints, the test fails.
// - expectedEps is the set of endpointnames to wait for. Typically this is also
//   the hostname reported by each pod in the service through /hostName.
// maxTries == minTries will confirm that we see the expected endpoints and no
// more for maxTries. Use this if you want to eg: fail a readiness check on a
// pod and confirm it doesn't show up as an endpoint.
func (config *NetworkingTestConfig) DialFromContainer(protocol, containerIP, targetIP string, containerHttpPort, targetPort, maxTries, minTries int, expectedEps sets.String) {
    cmd := fmt.Sprintf("curl -q -s 'http://%s:%d/dial?request=hostName&protocol=%s&host=%s&port=%d&tries=1'",
        containerIP,
        containerHttpPort,
        protocol,
        targetIP,
        targetPort)

    eps := sets.NewString()

    for i := 0; i < maxTries; i++ {
        stdout, stderr, err := config.f.ExecShellInPodWithFullOutput(config.HostTestContainerPod.Name, cmd)
        if err != nil {
            // A failure to kubectl exec counts as a try, not a hard fail.
            // Also note that we will keep failing for maxTries in tests where
            // we confirm unreachability.
            Logf("Failed to execute %q: %v, stdout: %q, stderr %q", cmd, err, stdout, stderr)
        } else {
            var output map[string][]string
            if err := json.Unmarshal([]byte(stdout), &output); err != nil {
                Logf("WARNING: Failed to unmarshal curl response. Cmd %v run in %v, output: %s, err: %v",
                    cmd, config.HostTestContainerPod.Name, stdout, err)
                continue
            }

            for _, hostName := range output["responses"] {
                trimmed := strings.TrimSpace(hostName)
                if trimmed != "" {
                    eps.Insert(trimmed)
                }
            }
        }
        Logf("Waiting for endpoints: %v", expectedEps.Difference(eps))

        // Check against i+1 so we exit if minTries == maxTries.
        if (eps.Equal(expectedEps) || eps.Len() == 0 && expectedEps.Len() == 0) && i+1 >= minTries {
            return
        }
        // TODO: get rid of this delay #36281
        time.Sleep(hitEndpointRetryDelay)
    }

    config.diagnoseMissingEndpoints(eps)
    Failf("Failed to find expected endpoints:\nTries %d\nCommand %v\nretrieved %v\nexpected %v\n", minTries, cmd, eps, expectedEps)
}
開發者ID:jonboulle,項目名稱:kubernetes,代碼行數:58,代碼來源:networking_utils.go

示例6: TestAdmissionOnOffCoverage

func TestAdmissionOnOffCoverage(t *testing.T) {
    configuredAdmissionPlugins := sets.NewString(origin.CombinedAdmissionControlPlugins...)
    allCoveredAdmissionPlugins := sets.String{}
    allCoveredAdmissionPlugins.Insert(defaultOnPlugins.List()...)
    allCoveredAdmissionPlugins.Insert(defaultOffPlugins.List()...)

    if !configuredAdmissionPlugins.Equal(allCoveredAdmissionPlugins) {
        t.Errorf("every admission plugin must be default on or default off. differences: %v and %v",
            configuredAdmissionPlugins.Difference(allCoveredAdmissionPlugins),
            allCoveredAdmissionPlugins.Difference(configuredAdmissionPlugins))
    }

    for plugin := range defaultOnPlugins {
        if defaultOffPlugins.Has(plugin) {
            t.Errorf("%v is both enabled and disabled", plugin)
        }
    }
}
開發者ID:ncdc,項目名稱:origin,代碼行數:18,代碼來源:admission_sync_test.go

示例7: DialFromNode

// DialFromNode executes a tcp or udp request based on protocol via kubectl exec
// in a test container running with host networking.
// - minTries is the minimum number of curl attempts required before declaring
//   success. Set to 0 if you'd like to return as soon as all endpoints respond
//   at least once.
// - maxTries is the maximum number of curl attempts. If this many attempts pass
//   and we don't see all expected endpoints, the test fails.
// maxTries == minTries will confirm that we see the expected endpoints and no
// more for maxTries. Use this if you want to eg: fail a readiness check on a
// pod and confirm it doesn't show up as an endpoint.
func (config *NetworkingTestConfig) DialFromNode(protocol, targetIP string, targetPort, maxTries, minTries int, expectedEps sets.String) {
    var cmd string
    if protocol == "udp" {
        // TODO: It would be enough to pass 1s+epsilon to timeout, but unfortunately
        // busybox timeout doesn't support non-integer values.
        cmd = fmt.Sprintf("echo 'hostName' | timeout -t 2 nc -w 1 -u %s %d", targetIP, targetPort)
    } else {
        cmd = fmt.Sprintf("timeout -t 15 curl -q -s --connect-timeout 1 http://%s:%d/hostName", targetIP, targetPort)
    }

    // TODO: This simply tells us that we can reach the endpoints. Check that
    // the probability of hitting a specific endpoint is roughly the same as
    // hitting any other.
    eps := sets.NewString()

    filterCmd := fmt.Sprintf("%s | grep -v '^\\s*$'", cmd)
    for i := 0; i < maxTries; i++ {
        stdout, stderr, err := config.f.ExecShellInPodWithFullOutput(config.HostTestContainerPod.Name, filterCmd)
        if err != nil || len(stderr) > 0 {
            // A failure to exec command counts as a try, not a hard fail.
            // Also note that we will keep failing for maxTries in tests where
            // we confirm unreachability.
            Logf("Failed to execute %q: %v, stdout: %q, stderr: %q", filterCmd, err, stdout, stderr)
        } else {
            trimmed := strings.TrimSpace(stdout)
            if trimmed != "" {
                eps.Insert(trimmed)
            }
        }
        Logf("Waiting for %+v endpoints, got endpoints %+v", expectedEps.Difference(eps), eps)

        // Check against i+1 so we exit if minTries == maxTries.
        if (eps.Equal(expectedEps) || eps.Len() == 0 && expectedEps.Len() == 0) && i+1 >= minTries {
            return
        }
        // TODO: get rid of this delay #36281
        time.Sleep(hitEndpointRetryDelay)
    }

    config.diagnoseMissingEndpoints(eps)
    Failf("Failed to find expected endpoints:\nTries %d\nCommand %v\nretrieved %v\nexpected %v\n", minTries, cmd, eps, expectedEps)
}
開發者ID:jonboulle,項目名稱:kubernetes,代碼行數:52,代碼來源:networking_utils.go

示例8: dialFromContainer

// dialFromContainers executes a curl via kubectl exec in a test container,
// which might then translate to a tcp or udp request based on the protocol
// argument in the url.
// - minTries is the minimum number of curl attempts required before declaring
//   success. Set to 0 if you'd like to return as soon as all endpoints respond
//   at least once.
// - maxTries is the maximum number of curl attempts. If this many attempts pass
//   and we don't see all expected endpoints, the test fails.
// - expectedEps is the set of endpointnames to wait for. Typically this is also
//   the hostname reported by each pod in the service through /hostName.
// maxTries == minTries will confirm that we see the expected endpoints and no
// more for maxTries. Use this if you want to eg: fail a readiness check on a
// pod and confirm it doesn't show up as an endpoint.
func (config *NetworkingTestConfig) dialFromContainer(protocol, containerIP, targetIP string, containerHttpPort, targetPort, maxTries, minTries int, expectedEps sets.String) {
    cmd := fmt.Sprintf("curl -q -s 'http://%s:%d/dial?request=hostName&protocol=%s&host=%s&port=%d&tries=1'",
        containerIP,
        containerHttpPort,
        protocol,
        targetIP,
        targetPort)

    eps := sets.NewString()

    for i := 0; i < maxTries; i++ {
        stdout, err := framework.RunHostCmd(config.ns, config.hostTestContainerPod.Name, cmd)
        if err != nil {
            // A failure to kubectl exec counts as a try, not a hard fail.
            // Also note that we will keep failing for maxTries in tests where
            // we confirm unreachability.
            framework.Logf("Failed to execute %v: %v", cmd, err)
        } else {
            var output map[string][]string
            if err := json.Unmarshal([]byte(stdout), &output); err != nil {
                framework.Logf("WARNING: Failed to unmarshal curl response. Cmd %v run in %v, output: %s, err: %v",
                    cmd, config.hostTestContainerPod.Name, stdout, err)
                continue
            }
            for _, hostName := range output["responses"] {
                eps.Insert(hostName)
            }
        }
        framework.Logf("Waiting for endpoints: %v", expectedEps.Difference(eps))

        // Check against i+1 so we exit if minTries == maxTries.
        if (eps.Equal(expectedEps) || eps.Len() == 0 && expectedEps.Len() == 0) && i+1 >= minTries {
            return
        }
    }

    config.diagnoseMissingEndpoints(eps)
    framework.Failf("Failed to find expected endpoints:\nTries %d\nCommand %v\nretrieved %v\nexpected %v\n", minTries, cmd, eps, expectedEps)
}
開發者ID:cheld,項目名稱:kubernetes,代碼行數:52,代碼來源:networking_utils.go

示例9: notifyWatchers

func (ac *AuthorizationCache) notifyWatchers(namespace string, exists *reviewRecord, latestUsers, latestGroups sets.String) {
    existingGroups := sets.String{}
    existingUsers := sets.String{}
    if exists != nil {
        existingGroups = sets.NewString(exists.groups...)
        existingUsers = sets.NewString(exists.users...)
    }

    // calculate once to avoid fanning out.
    removedUsers := existingUsers.Difference(latestUsers)
    removedGroups := existingGroups.Difference(latestGroups)
    addedUsers := latestUsers.Difference(existingUsers)
    addedGroups := latestGroups.Difference(existingGroups)

    ac.watcherLock.Lock()
    defer ac.watcherLock.Unlock()
    for _, watcher := range ac.watchers {
        watcher.GroupMembershipChanged(namespace, latestUsers, latestGroups, removedUsers, removedGroups, addedUsers, addedGroups)
    }
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:20,代碼來源:cache.go


注:本文中的k8s/io/kubernetes/pkg/util/sets.String.Difference方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。