upgrade kubefed client to v0.6.1

Signed-off-by: yuswift <yuswiftli@yunify.com>
This commit is contained in:
yuswift
2021-04-06 17:52:54 +08:00
parent 828d2c6d37
commit 82cd5c454e
12 changed files with 66 additions and 70 deletions

View File

@@ -20,7 +20,7 @@ import (
"fmt"
"strings"
apiextv1b1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/kubefed/pkg/apis/core/common"
@@ -66,7 +66,7 @@ type APIResource struct {
// suffixing an 's'.
PluralName string `json:"pluralName"`
// Scope of the resource.
Scope apiextv1b1.ResourceScope `json:"scope"`
Scope apiextv1.ResourceScope `json:"scope"`
}
// PropagationMode defines the state of propagation to member clusters.
@@ -207,18 +207,20 @@ func (f *FederatedTypeConfig) GetFederatedType() metav1.APIResource {
return apiResourceToMeta(f.Spec.FederatedType, f.GetFederatedNamespaced())
}
// TODO (hectorj2f): It should get deprecated once we move to the new status approach
// because the type is the same as the target type.
func (f *FederatedTypeConfig) GetStatusType() *metav1.APIResource {
if f.Spec.StatusType == nil {
return nil
}
// Return the original target type
metaAPIResource := apiResourceToMeta(*f.Spec.StatusType, f.Spec.StatusType.Namespaced())
return &metaAPIResource
}
func (f *FederatedTypeConfig) GetStatusEnabled() bool {
return f.Spec.StatusCollection != nil &&
*f.Spec.StatusCollection == StatusCollectionEnabled &&
f.Name == "services"
*f.Spec.StatusCollection == StatusCollectionEnabled
}
// TODO(font): This method should be removed from the interface i.e. remove
@@ -243,7 +245,7 @@ func (f *FederatedTypeConfig) IsNamespace() bool {
}
func (a *APIResource) Namespaced() bool {
return a.Scope == apiextv1b1.NamespaceScoped
return a.Scope == apiextv1.NamespaceScoped
}
func apiResourceToMeta(apiResource APIResource, namespaced bool) metav1.APIResource {

View File

@@ -17,7 +17,7 @@ limitations under the License.
package v1beta1
import (
apiextv1b1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@@ -26,7 +26,7 @@ type KubeFedConfigSpec struct {
// The scope of the KubeFed control plane should be either
// `Namespaced` or `Cluster`. `Namespaced` indicates that the
// KubeFed namespace will be the only target of the control plane.
Scope apiextv1b1.ResourceScope `json:"scope"`
Scope apiextv1.ResourceScope `json:"scope"`
// +optional
ControllerDuration *DurationConfig `json:"controllerDuration,omitempty"`
// +optional

View File

@@ -22,7 +22,7 @@ import (
// ReplicaSchedulingPreferenceSpec defines the desired state of ReplicaSchedulingPreference
type ReplicaSchedulingPreferenceSpec struct {
//TODO (@irfanurrehman); upgrade this to label selector only if need be.
// TODO (@irfanurrehman); upgrade this to label selector only if need be.
// The idea of this API is to have a a set of preferences which can
// be used for a target FederatedDeployment or FederatedReplicaset.
// Although the set of preferences in question can be applied to multiple
@@ -75,7 +75,7 @@ type ReplicaSchedulingPreferenceStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=replicaschedulingpreferences
// +kubebuilder:resource:path=replicaschedulingpreferences,shortName=rsp
type ReplicaSchedulingPreference struct {
metav1.TypeMeta `json:",inline"`

View File

@@ -68,11 +68,12 @@ type ClusterHealthCheckConfig struct {
// controllers.
type ControllerConfig struct {
KubeFedNamespaces
KubeConfig *restclient.Config
ClusterAvailableDelay time.Duration
ClusterUnavailableDelay time.Duration
MinimizeLatency bool
SkipAdoptingResources bool
KubeConfig *restclient.Config
ClusterAvailableDelay time.Duration
ClusterUnavailableDelay time.Duration
MinimizeLatency bool
SkipAdoptingResources bool
RawResourceStatusCollection bool
}
func (c *ControllerConfig) LimitedScope() bool {

View File

@@ -141,7 +141,6 @@ func NewFederatedInformer(
apiResource *metav1.APIResource,
triggerFunc func(pkgruntime.Object),
clusterLifecycle *ClusterLifecycleHandlerFuncs) (FederatedInformer, error) {
targetInformerFactory := func(cluster *fedv1b1.KubeFedCluster, clusterConfig *restclient.Config) (cache.Store, cache.Controller, error) {
resourceClient, err := NewResourceClient(clusterConfig, apiResource)
if err != nil {
@@ -201,15 +200,16 @@ func NewFederatedInformer(
},
AddFunc: func(cur interface{}) {
curCluster, ok := cur.(*fedv1b1.KubeFedCluster)
if !ok {
switch {
case !ok:
klog.Errorf("Cluster %v/%v not added; incorrect type", curCluster.Namespace, curCluster.Name)
} else if IsClusterReady(&curCluster.Status) {
case IsClusterReady(&curCluster.Status):
federatedInformer.addCluster(curCluster)
klog.Infof("Cluster %v/%v is ready", curCluster.Namespace, curCluster.Name)
if clusterLifecycle.ClusterAvailable != nil {
clusterLifecycle.ClusterAvailable(curCluster)
}
} else {
default:
klog.Infof("Cluster %v/%v not added; it is not ready.", curCluster.Namespace, curCluster.Name)
}
},
@@ -348,10 +348,8 @@ func (f *federatedInformerImpl) getConfigForClusterUnlocked(clusterName string)
klog.V(4).Infof("Getting config for cluster %q", clusterName)
if cluster, found, err := f.getReadyClusterUnlocked(clusterName); found && err == nil {
return f.configFactory(cluster)
} else {
if err != nil {
return nil, err
}
} else if err != nil {
return nil, err
}
return nil, errors.Errorf("cluster %q not found", clusterName)
}
@@ -418,10 +416,8 @@ func (f *federatedInformerImpl) getReadyClusterUnlocked(name string) (*fedv1b1.K
return cluster, true, nil
}
return nil, false, nil
}
return nil, false, errors.Errorf("wrong data in FederatedInformerImpl cluster store: %v", obj)
} else {
return nil, false, err
}
@@ -541,7 +537,6 @@ func (fs *federatedStoreImpl) GetKeyFor(item interface{}) string {
// Checks whether stores for all clusters form the lists (and only these) are there and
// are synced.
func (fs *federatedStoreImpl) ClustersSynced(clusters []*fedv1b1.KubeFedCluster) bool {
// Get the list of informers to check under a lock and check it outside.
okSoFar, informersToCheck := func() (bool, []informer) {
fs.federatedInformer.Lock()

View File

@@ -26,7 +26,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
pkgruntime "k8s.io/apimachinery/pkg/runtime"
)
// Copies cluster-independent, user provided data from the given ObjectMeta struct. If in
@@ -114,7 +113,7 @@ func ObjectMetaAndSpecEquivalent(a, b runtime.Object) bool {
return ObjectMetaEquivalent(objectMetaA, objectMetaB) && reflect.DeepEqual(specA, specB)
}
func MetaAccessor(obj pkgruntime.Object) metav1.Object {
func MetaAccessor(obj runtime.Object) metav1.Object {
accessor, err := meta.Accessor(obj)
if err != nil {
// This should always succeed if obj is not nil. Also,

View File

@@ -19,7 +19,7 @@ package util
import (
"encoding/json"
"github.com/evanphx/json-patch"
jsonpatch "github.com/evanphx/json-patch"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -159,8 +159,8 @@ func UnstructuredToInterface(rawObj *unstructured.Unstructured, obj interface{})
return json.Unmarshal(content, obj)
}
// ApplyJsonPatch applies the override on to the given unstructured object.
func ApplyJsonPatch(obj *unstructured.Unstructured, overrides ClusterOverrides) error {
// ApplyJSONPatch applies the override on to the given unstructured object.
func ApplyJSONPatch(obj *unstructured.Unstructured, overrides ClusterOverrides) error {
// TODO: Do the defaulting of "op" field to "replace" in API defaulting
for i, overrideItem := range overrides {
if overrideItem.Op == "" {
@@ -177,12 +177,12 @@ func ApplyJsonPatch(obj *unstructured.Unstructured, overrides ClusterOverrides)
return err
}
ObjectJSONBytes, err := obj.MarshalJSON()
objectJSONBytes, err := obj.MarshalJSON()
if err != nil {
return err
}
patchedObjectJSONBytes, err := patch.Apply(ObjectJSONBytes)
patchedObjectJSONBytes, err := patch.Apply(objectJSONBytes)
if err != nil {
return err
}

View File

@@ -137,7 +137,7 @@ func (w *asyncWorker) deliver(qualifiedName QualifiedName, delay time.Duration,
key := qualifiedName.String()
if failed {
w.backoff.Next(key, time.Now())
delay = delay + w.backoff.Get(key)
delay += w.backoff.Get(key)
} else {
w.backoff.Reset(key)
}

View File

@@ -22,7 +22,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/pflag"
apiextv1b1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
@@ -101,7 +101,7 @@ func (o *CommonJoinOptions) SetName(args []string) error {
return nil
}
func GetScopeFromKubeFedConfig(hostConfig *rest.Config, namespace string) (apiextv1b1.ResourceScope, error) {
func GetScopeFromKubeFedConfig(hostConfig *rest.Config, namespace string) (apiextv1.ResourceScope, error) {
client, err := genericclient.New(hostConfig)
if err != nil {
err = errors.Wrap(err, "Failed to get kubefed clientset")