Skip to content

Commit

Permalink
enhancement (CollaSet): fix linter and ut
Browse files Browse the repository at this point in the history
  • Loading branch information
wu8685 committed Aug 10, 2023
1 parent 0c99ffe commit e0c8fc0
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 6,866 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Image URL to use all building/pushing image targets
IMG ?= controller:202307101
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0
ENVTEST_K8S_VERSION = 1.22.6
# kind cluster name for e2e
CLUSTER_NAME ?= kindcluster
# kind version for e2e
Expand Down
2 changes: 2 additions & 0 deletions apis/apps/v1alpha1/collaset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ type CollaSetSpec struct {
// insufficient replicas are detected. Each pod stamped out by the CollaSet
// will fulfill this Template, but have a unique identity from the rest
// of the CollaSet.
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Template corev1.PodTemplateSpec `json:"template,omitempty"`

// VolumeClaimTemplates is a list of claims that pods are allowed to reference.
Expand Down
6,856 changes: 3 additions & 6,853 deletions config/crd/bases/apps.kafed.io_collasets.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion config/crd/bases/apps.kafed.io_resourcecontexts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.12.0
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: resourcecontexts.apps.kafed.io
spec:
group: apps.kafed.io
Expand Down
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/collaset/synccontrol/sync_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (sc *RealSyncControl) Scale(set *appsv1alpha1.CollaSet, podWrappers []*coll
// find IDs and their contexts which have not been used by owned Pods
availableContext := extractAvailableContexts(diff, ownedIDs, podInstanceIDSet)

succCount, err := controllerutils.SlowStartBatch(diff, controllerutils.SlowStartInitialBatchSize, false, func(idx int, err error) error {
succCount, err := controllerutils.SlowStartBatch(diff, controllerutils.SlowStartInitialBatchSize, false, func(idx int, _ error) error {
availableIDContext := availableContext[idx]
// use revision recorded in Context
revision := updatedRevision
Expand Down
6 changes: 3 additions & 3 deletions pkg/controllers/utils/expectations/active_expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (ae *ActiveExpectations) expect(subject metav1.Object, kind ExpectedReosurc
}

if action == Update {
panic(fmt.Sprintf("update action is not supported by this method"))
panic("update action is not supported by this method")
}

key := fmt.Sprintf("%s/%s", subject.GetNamespace(), subject.GetName())
Expand Down Expand Up @@ -275,7 +275,7 @@ type ActiveExpectation struct {

func (ae *ActiveExpectation) expect(kind ExpectedReosurceType, name string, action ActiveExpectationAction) error {
if action == Update {
panic(fmt.Sprintf("update action is not supported by this method"))
panic("update action is not supported by this method")
}

key := fmt.Sprintf("%s/%s", kind, name)
Expand Down Expand Up @@ -334,7 +334,7 @@ func (ae *ActiveExpectation) isSatisfied() (satisfied bool, err error) {
if satisfied {
ae.items.Delete(item)
} else if ae.recordTimestamp.Add(ExpectationsTimeout).Before(time.Now()) {
panic(fmt.Sprintf("expected panic for active expectation"))
panic("expected panic for active expectation")
}
}()

Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/utils/podopslifecycle/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func Finish(c client.Client, adapter LifecycleAdapter, obj client.Object) (updat
operationType, hasType := checkOperationType(adapter, obj)

if hasType && operationType != adapter.GetType() {
err = fmt.Errorf("operatingID %s has invalid operationType %s", operatingID, operationType)
return false, fmt.Errorf("operatingID %s has invalid operationType %s", operatingID, operationType)
}

var needUpdate bool
Expand All @@ -126,7 +126,7 @@ func Finish(c client.Client, adapter LifecycleAdapter, obj client.Object) (updat

func checkOperatingID(adapter LifecycleAdapter, obj client.Object) (val string, ok bool) {
labelID := fmt.Sprintf("%s/%s", v1alpha1.PodOperatingLabelPrefix, adapter.GetID())
val, ok = obj.GetLabels()[labelID]
_, ok = obj.GetLabels()[labelID]
return adapter.GetID(), ok
}

Expand Down
5 changes: 0 additions & 5 deletions pkg/controllers/utils/refmanager/ref_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package utils
import (
"context"
"fmt"
"reflect"
"sync"

apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -48,10 +47,6 @@ func NewRefManager(client client.Writer, selector *metav1.LabelSelector, owner m
return nil, err
}

ownerType := reflect.TypeOf(owner)
if ownerType.Kind() == reflect.Ptr {
ownerType = ownerType.Elem()
}
return &RefManager{
client: client,
selector: s,
Expand Down
3 changes: 3 additions & 0 deletions pkg/controllers/utils/revision/revision_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func controlledHistories(c client.Client, owner client.Object, labelSelector *me

// Use ControllerRefManager to adopt/orphan as needed.
cm, err := refmanagerutil.NewRefManager(c, labelSelector, owner, scheme)
if err != nil {
return nil, err
}
mts := make([]client.Object, len(histories.Items))
for i, pod := range histories.Items {
mts[i] = pod.DeepCopy()
Expand Down

0 comments on commit e0c8fc0

Please sign in to comment.