Skip to content

Commit

Permalink
fix failed actions
Browse files Browse the repository at this point in the history
  • Loading branch information
shaofan-hs committed Jan 8, 2024
1 parent 149a8f6 commit 226d7eb
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 37 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ jobs:
run: |
make test
git status
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
flags: unittests
file: cover.out
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Check diff
run: '[[ -z $(git status -s) ]] || (printf "Existing modified/untracked files.\nPlease run \"make generate manifests fmt vet\" and push again.\n"; exit 1)'
GolangLint:
name: Golang Lint
Expand Down
64 changes: 64 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
header:
license:
content: |
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
paths:
- '**'
paths-ignore:
- '**/*.conf'
- '**/*.DS_Store'
- '**/*.json'
- '**/*.lock'
- '**/*.Dockerfile'
- '**/*.sh'
- '**/*.yaml'
- '**/*.md'
- '**/*.mk'
- '**/*.svg'
- '**/*.txt'
- '**/*.xlf'
- '**/.husky/**'
- '**/node_modules/**'
- '**/.babelrc'
- '**/.browserslistrc'
- '**/.editorconfig'
- '**/.jsbeautifyrc'
- '**/.yarnrc.yml'
- '**/config_repos'
- '**/go.mod'
- '**/go.sum'
- '**/go.work'
- '**/go.work.sum'
- '**/lcov.info'
- '**/Makefile'
- '**/OWNERS'
- '.github/**'
- '.idea/**'
- '.vscode/**'
- '.dist/**'
- '.husky/**'
- 'hack/**'
- 'LICENSE'
- 'OWNERS_ALIASES'
- 'SECURITY_CONTACTS'
- 'vendor/**'
- '.gitignore'
- '.licenserc'
- '**/zz_generated.deepcopy.go'
- '**/*.pb.go'
- '**/*.proto'
- '**/PROJECT'
- '**/Dockerfile'
- '**/.dockerignore'
comment: never
license-location-threshold: 80
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.22.1

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

.PHONY: test
test: fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

##@ Build Dependencies

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

ENVTEST ?= $(LOCALBIN)/setup-envtest

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
34 changes: 14 additions & 20 deletions cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

const (
Expand All @@ -45,11 +44,10 @@ const (
)

var (
env *envtest.Environment
mgr manager.Manager
request chan reconcile.Request
pod *corev1.Pod
deploy *appsv1.Deployment
env *envtest.Environment
mgr manager.Manager
pod *corev1.Pod
deploy *appsv1.Deployment

c client.Client
)
Expand Down Expand Up @@ -114,8 +112,8 @@ var _ = Describe("cache support no DeepCopy", func() {
})
})

func initPod() *corev1.Pod {
pod := &corev1.Pod{
func initPod() {
pod = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "foo",
Expand All @@ -141,12 +139,10 @@ func initPod() *corev1.Pod {
Eventually(func() bool {
return c.Get(context.TODO(), types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name}, pod) == nil
}, 5*time.Second, 1*time.Second).Should(BeTrue())

return pod
}

func initDeploy() *appsv1.Deployment {
deploy := &appsv1.Deployment{
func initDeploy() {
deploy = &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "foo",
Expand Down Expand Up @@ -178,8 +174,6 @@ func initDeploy() *appsv1.Deployment {
Eventually(func() bool {
return c.Get(context.TODO(), types.NamespacedName{Namespace: deploy.Namespace, Name: deploy.Name}, deploy) == nil
}, 5*time.Second, 1*time.Second).Should(BeTrue())

return deploy
}

func TestCache(t *testing.T) {
Expand Down Expand Up @@ -208,21 +202,21 @@ var _ = BeforeSuite(func() {

c := mgr.GetCache()
c.IndexField(context.TODO(), &corev1.Pod{}, TestPodNamespaceFieldIndex, func(obj client.Object) []string {
pod := obj.(*corev1.Pod)
return []string{pod.Namespace}
po := obj.(*corev1.Pod)
return []string{po.Namespace}
})
c.IndexField(context.TODO(), &corev1.Pod{}, TestPodContainerNumberFieldIndex, func(obj client.Object) []string {
pod := obj.(*corev1.Pod)
return []string{fmt.Sprintf("%d", len(pod.Spec.Containers))}
po := obj.(*corev1.Pod)
return []string{fmt.Sprintf("%d", len(po.Spec.Containers))}
})

go func() {
err = mgr.Start(context.TODO())
Expect(err).NotTo(HaveOccurred())
}()

pod = initPod()
deploy = initDeploy()
initPod()
initDeploy()
})

var _ = AfterSuite(func() {
Expand Down
1 change: 0 additions & 1 deletion controller/workqueue/priority_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ func (q *PriorityQueue) Done(item interface{}) {

q.processing.delete(item)
if q.dirty.has(item) {

q.priorityQueue[priority] = append(q.priorityQueue[priority], item)
q.count++
klog.V(5).Infof("Add item to priority queue from dirty, priority: %v, count: %v", priority, q.count)
Expand Down
16 changes: 16 additions & 0 deletions controller/workqueue/suite_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**
* Copyright 2024 KusionStack Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package workqueue

import (
Expand Down
4 changes: 2 additions & 2 deletions multicluster/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ var _ = Describe("help", func() {
podList, ok := podListObj.(*corev1.PodList)
Expect(ok).To(BeTrue())
for _, pod := range podList.Items {
cluster, ok := pod.GetLabels()[clusterinfo.ClusterLabelKey]
Expect(ok).To(BeTrue())
cluster, ok1 := pod.GetLabels()[clusterinfo.ClusterLabelKey]
Expect(ok1).To(BeTrue())
Expect(cluster).To(Equal("cluster1"))
}

Expand Down
3 changes: 2 additions & 1 deletion multicluster/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,9 @@ var _ = Describe("multicluster with 1 fed and 4 clusters", func() {
})

func newMockClient() *MockClient {
clientBuilder := fake.NewClientBuilder()
return &MockClient{
WithWatch: fake.NewFakeClient(),
WithWatch: clientBuilder.Build(),
}
}

Expand Down
12 changes: 8 additions & 4 deletions multicluster/multi_cluster_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,16 +570,20 @@ func (mci *multiClusterInformer) addClusterInformer(cluster string, clusterInfor
mci.mutex.Lock()
defer mci.mutex.Unlock()

if mci.indexers != nil {
err := clusterInformer.AddIndexers(mci.indexers)
if err != nil {
mci.log.Error(err, "failed to add indexer", "cluster", cluster)
return
}
}

if mci.handler != nil && mci.resyncPeriod != 0 {
clusterInformer.AddEventHandlerWithResyncPeriod(mci.handler, mci.resyncPeriod)
} else if mci.handler != nil {
clusterInformer.AddEventHandler(mci.handler)
}

if mci.indexers != nil {
clusterInformer.AddIndexers(mci.indexers)
}

mci.clusterToInformer[cluster] = clusterInformer
}

Expand Down

0 comments on commit 226d7eb

Please sign in to comment.