Skip to content

Commit

Permalink
Merge pull request #732 from ESonata/update-aliases
Browse files Browse the repository at this point in the history
update import-aliases
  • Loading branch information
karmada-bot authored Sep 16, 2021
2 parents dd369f8 + a6165e4 commit c3cf3a3
Show file tree
Hide file tree
Showing 39 changed files with 264 additions and 251 deletions.
5 changes: 3 additions & 2 deletions hack/.import-aliases
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"k8s.io/api/certificates/v1beta1": "certificatesv1beta1",
"k8s.io/api/coordination/v1": "coordinationv1",
"k8s.io/api/coordination/v1beta1": "coordinationv1beta1",
"k8s.io/api/core/v1": "v1",
"k8s.io/api/core/v1": "corev1",
"k8s.io/api/discovery/v1alpha1": "discoveryv1alpha1",
"k8s.io/api/discovery/v1beta1": "discoveryv1beta1",
"k8s.io/api/events/v1": "eventsv1",
Expand All @@ -40,8 +40,9 @@
"k8s.io/api/storage/v1alpha1": "storagev1alpha1",
"k8s.io/api/storage/v1beta1": "storagev1beta1",
"k8s.io/apimachinery/pkg/api/errors": "apierrors",
"k8s.io/apimachinery/pkg/apis/meta/v1": "metav1",
"k8s.io/kubelet/apis/stats/v1alpha1": "kubeletstatsv1alpha1",
"k8s.io/kubernetes/pk g/controller/apis/config/v1alpha1": "controllerconfigv1alpha1",
"k8s.io/kubernetes/pkg/controller/apis/config/v1alpha1": "controllerconfigv1alpha1",
"k8s.io/kubernetes/pkg/kubelet/apis/config/v1beta1": "kubeletconfigv1beta1",
"k8s.io/kubelet/pkg/apis/deviceplugin/v1alpha": "kubeletdevicepluginv1alpha",
"k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1": "kubeletdevicepluginv1beta1",
Expand Down
16 changes: 14 additions & 2 deletions hack/update-import-aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@ temp_path=$(mktemp -d)
pushd "${temp_path}" >/dev/null
cp "${ROOT_PATH}"/go.mod .
GO111MODULE=on go get "k8s.io/kubernetes/cmd/[email protected]"
GO111MODULE=on go get "golang.org/x/tools/cmd/[email protected]"
popd >/dev/null

IMPORT_ALIASES_PATH="${ROOT_PATH}/hack/.import-aliases"
INCLUDE_PATH="(${ROOT_PATH}/cmd|${ROOT_PATH}/test/e2e|${ROOT_PATH}/test/helper|\
${ROOT_PATH}/pkg/apis|${ROOT_PATH}/pkg/clusterdiscovery|${ROOT_PATH}/pkg/controllers|\
${ROOT_PATH}/pkg/estimator|${ROOT_PATH}/pkg/karmadactl|${ROOT_PATH}/pkg/scheduler|\
${ROOT_PATH}/pkg/clusterdiscovery|${ROOT_PATH}/pkg/controllers|\
${ROOT_PATH}/pkg/estimator/server|${ROOT_PATH}/pkg/karmadactl|${ROOT_PATH}/pkg/scheduler|\
${ROOT_PATH}/pkg/util|${ROOT_PATH}/pkg/version|${ROOT_PATH}/pkg/webhook)"

preferredimports -confirm -import-aliases "${IMPORT_ALIASES_PATH}" -include-path "${INCLUDE_PATH}" "${ROOT_PATH}"

len=${#INCLUDE_PATH}
INCLUDE_PATH=${INCLUDE_PATH:1:len-2}

IFS="|" read -r -a array <<< "${INCLUDE_PATH}"
for var in "${array[@]}"
do
echo "Sorting importing in file" "${var}"
goimports -local "github.com/karmada-io/karmada" -w "${var}"
done

4 changes: 2 additions & 2 deletions hack/verify-import-aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ popd >/dev/null

IMPORT_ALIASES_PATH="${ROOT_PATH}/hack/.import-aliases"
INCLUDE_PATH="(${ROOT_PATH}/cmd|${ROOT_PATH}/test/e2e|${ROOT_PATH}/test/helper|\
${ROOT_PATH}/pkg/apis|${ROOT_PATH}/pkg/clusterdiscovery|${ROOT_PATH}/pkg/controllers|\
${ROOT_PATH}/pkg/estimator|${ROOT_PATH}/pkg/karmadactl|${ROOT_PATH}/pkg/scheduler|\
${ROOT_PATH}/pkg/clusterdiscovery|${ROOT_PATH}/pkg/controllers|\
${ROOT_PATH}/pkg/estimator/server|${ROOT_PATH}/pkg/karmadactl|${ROOT_PATH}/pkg/scheduler|\
${ROOT_PATH}/pkg/util|${ROOT_PATH}/pkg/version|${ROOT_PATH}/pkg/webhook)"

ret=0
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/binding/binding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -45,7 +45,7 @@ func (c *ResourceBindingController) Reconcile(ctx context.Context, req controlle
binding := &workv1alpha1.ResourceBinding{}
if err := c.Client.Get(context.TODO(), req.NamespacedName, binding); err != nil {
// The resource no longer exist, clean up derived Work objects.
if errors.IsNotFound(err) {
if apierrors.IsNotFound(err) {
return helper.DeleteWorks(c.Client, labels.Set{
workv1alpha1.ResourceBindingNamespaceLabel: req.Namespace,
workv1alpha1.ResourceBindingNameLabel: req.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -45,7 +45,7 @@ func (c *ClusterResourceBindingController) Reconcile(ctx context.Context, req co
clusterResourceBinding := &workv1alpha1.ClusterResourceBinding{}
if err := c.Client.Get(context.TODO(), req.NamespacedName, clusterResourceBinding); err != nil {
// The resource no longer exist, clean up derived Work objects.
if errors.IsNotFound(err) {
if apierrors.IsNotFound(err) {
return helper.DeleteWorks(c.Client, labels.Set{
workv1alpha1.ClusterResourceBindingLabel: req.Name,
})
Expand Down
18 changes: 9 additions & 9 deletions pkg/controllers/binding/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"

clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
workv1alpha1 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/helper"
Expand Down Expand Up @@ -117,7 +117,7 @@ func ensureWork(c client.Client, workload *unstructured.Unstructured, overrideMa
return nil
}

func getRSPAndReplicaInfos(c client.Client, workload *unstructured.Unstructured, targetClusters []workv1alpha1.TargetCluster) (bool, *v1alpha1.ReplicaSchedulingPolicy, map[string]int64, error) {
func getRSPAndReplicaInfos(c client.Client, workload *unstructured.Unstructured, targetClusters []workv1alpha1.TargetCluster) (bool, *policyv1alpha1.ReplicaSchedulingPolicy, map[string]int64, error) {
if helper.HasScheduledReplica(targetClusters) {
return true, nil, transScheduleResultToMap(targetClusters), nil
}
Expand Down Expand Up @@ -197,9 +197,9 @@ func transScheduleResultToMap(scheduleResult []workv1alpha1.TargetCluster) map[s
return desireReplicaInfos
}

func calculateReplicasIfNeeded(c client.Client, workload *unstructured.Unstructured, clusterNames []string) (*v1alpha1.ReplicaSchedulingPolicy, map[string]int64, error) {
func calculateReplicasIfNeeded(c client.Client, workload *unstructured.Unstructured, clusterNames []string) (*policyv1alpha1.ReplicaSchedulingPolicy, map[string]int64, error) {
var err error
var referenceRSP *v1alpha1.ReplicaSchedulingPolicy
var referenceRSP *policyv1alpha1.ReplicaSchedulingPolicy
var desireReplicaInfos = make(map[string]int64)

if workload.GetKind() == util.DeploymentKind {
Expand All @@ -219,9 +219,9 @@ func calculateReplicasIfNeeded(c client.Client, workload *unstructured.Unstructu
return referenceRSP, desireReplicaInfos, nil
}

func matchReplicaSchedulingPolicy(c client.Client, workload *unstructured.Unstructured) (*v1alpha1.ReplicaSchedulingPolicy, error) {
func matchReplicaSchedulingPolicy(c client.Client, workload *unstructured.Unstructured) (*policyv1alpha1.ReplicaSchedulingPolicy, error) {
// get all namespace-scoped replica scheduling policies
policyList := &v1alpha1.ReplicaSchedulingPolicyList{}
policyList := &policyv1alpha1.ReplicaSchedulingPolicyList{}
if err := c.List(context.TODO(), policyList, &client.ListOptions{Namespace: workload.GetNamespace()}); err != nil {
klog.Errorf("Failed to list replica scheduling policies from namespace: %s, error: %v", workload.GetNamespace(), err)
return nil, err
Expand All @@ -240,9 +240,9 @@ func matchReplicaSchedulingPolicy(c client.Client, workload *unstructured.Unstru
return &matchedPolicies[0], nil
}

func getMatchedReplicaSchedulingPolicy(policies []v1alpha1.ReplicaSchedulingPolicy, resource *unstructured.Unstructured) []v1alpha1.ReplicaSchedulingPolicy {
func getMatchedReplicaSchedulingPolicy(policies []policyv1alpha1.ReplicaSchedulingPolicy, resource *unstructured.Unstructured) []policyv1alpha1.ReplicaSchedulingPolicy {
// select policy in which at least one resource selector matches target resource.
resourceMatches := make([]v1alpha1.ReplicaSchedulingPolicy, 0)
resourceMatches := make([]policyv1alpha1.ReplicaSchedulingPolicy, 0)
for _, policy := range policies {
if util.ResourceMatchSelectors(resource, policy.Spec.ResourceSelectors...) {
resourceMatches = append(resourceMatches, policy)
Expand All @@ -257,7 +257,7 @@ func getMatchedReplicaSchedulingPolicy(policies []v1alpha1.ReplicaSchedulingPoli
return resourceMatches
}

func calculateReplicas(c client.Client, policy *v1alpha1.ReplicaSchedulingPolicy, clusterNames []string) (map[string]int64, error) {
func calculateReplicas(c client.Client, policy *policyv1alpha1.ReplicaSchedulingPolicy, clusterNames []string) (map[string]int64, error) {
weightSum := int64(0)
matchClusters := make(map[string]int64)
desireReplicaInfos := make(map[string]int64)
Expand Down
Loading

0 comments on commit c3cf3a3

Please sign in to comment.