update vendor

Signed-off-by: Roland.Ma <rolandma@yunify.com>
This commit is contained in:
Roland.Ma
2021-08-11 07:10:14 +00:00
parent a18f72b565
commit ea8f47c73a
2901 changed files with 269317 additions and 43103 deletions

View File

@@ -20,6 +20,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/sets"
fedv1b1 "sigs.k8s.io/kubefed/pkg/apis/core/v1beta1"
)
type GenericClusterReference struct {
@@ -86,3 +89,96 @@ func SetClusterNames(obj *unstructured.Unstructured, clusterNames []string) erro
}
return unstructured.SetNestedSlice(obj.Object, clusters, SpecField, PlacementField, ClustersField)
}
func SetClusterSelector(obj *unstructured.Unstructured, clusterSelector map[string]string) error {
return unstructured.SetNestedStringMap(obj.Object, clusterSelector, SpecField, PlacementField, ClusterSelectorField, MatchLabelsField)
}
// ComputeNamespacedPlacement determines placement for namespaced
// federated resources (e.g. FederatedConfigMap).
//
// If KubeFed is deployed cluster-wide, placement is the intersection
// of the placement for the federated resource and the placement of
// the federated namespace containing the resource.
//
// If KubeFed is limited to a single namespace, placement is
// determined as the intersection of resource and namespace placement
// if namespace placement exists. If namespace placement does not
// exist, resource placement will be used verbatim. This is possible
// because the single namespace by definition must exist on member
// clusters, so namespace placement becomes a mechanism for limiting
// rather than allowing propagation.
func ComputeNamespacedPlacement(resource, namespace *unstructured.Unstructured, clusters []*fedv1b1.KubeFedCluster, limitedScope bool, selectorOnly bool) (selectedClusters sets.String, err error) {
resourceClusters, err := ComputePlacement(resource, clusters, selectorOnly)
if err != nil {
return nil, err
}
if namespace == nil {
if limitedScope {
// Use the resource placement verbatim if no federated
// namespace is present and KubeFed is targeting a
// single namespace.
return resourceClusters, nil
}
// Resource should not exist in any member clusters.
return sets.String{}, nil
}
namespaceClusters, err := ComputePlacement(namespace, clusters, selectorOnly)
if err != nil {
return nil, err
}
// If both namespace and resource placement exist, the desired
// list of clusters is their intersection.
return resourceClusters.Intersection(namespaceClusters), nil
}
// ComputePlacement determines the selected clusters for a federated
// resource.
func ComputePlacement(resource *unstructured.Unstructured, clusters []*fedv1b1.KubeFedCluster, selectorOnly bool) (selectedClusters sets.String, err error) {
selectedNames, err := selectedClusterNames(resource, clusters, selectorOnly)
if err != nil {
return nil, err
}
clusterNames := getClusterNames(clusters)
return clusterNames.Intersection(selectedNames), nil
}
func selectedClusterNames(resource *unstructured.Unstructured, clusters []*fedv1b1.KubeFedCluster, selectorOnly bool) (sets.String, error) {
placement, err := UnmarshalGenericPlacement(resource)
if err != nil {
return nil, err
}
selectedNames := sets.String{}
clusterNames := placement.ClusterNames()
// Only use selector if clusters are nil. An empty list of
// clusters implies no clusters are selected.
if selectorOnly || clusterNames == nil {
selector, err := placement.ClusterSelector()
if err != nil {
return nil, err
}
for _, cluster := range clusters {
if selector.Matches(labels.Set(cluster.Labels)) {
selectedNames.Insert(cluster.Name)
}
}
} else {
for _, clusterName := range clusterNames {
selectedNames.Insert(clusterName)
}
}
return selectedNames, nil
}
func getClusterNames(clusters []*fedv1b1.KubeFedCluster) sets.String {
clusterNames := sets.String{}
for _, cluster := range clusters {
clusterNames.Insert(cluster.Name)
}
return clusterNames
}