Skip to content

Commit

Permalink
[Enhancement] add unit test, and make sure code coverage >60% (#352)
Browse files Browse the repository at this point in the history
* [Chore] update vendor directory

Signed-off-by: yandongxiao <[email protected]>

* [Enhancement] add unit test, and make sure code coverage >60%

Signed-off-by: yandongxiao <[email protected]>

---------

Signed-off-by: yandongxiao <[email protected]>
  • Loading branch information
yandongxiao authored Dec 11, 2023
1 parent 1f36c78 commit 4c6d5dc
Show file tree
Hide file tree
Showing 188 changed files with 3,458 additions and 24,139 deletions.
16 changes: 4 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,23 @@ module github.com/StarRocks/starrocks-kubernetes-operator
go 1.19

require (
github.com/DATA-DOG/go-sqlmock v1.5.1
github.com/davecgh/go-spew v1.1.1
github.com/go-logr/logr v1.2.3
github.com/go-sql-driver/mysql v1.7.1
github.com/onsi/ginkgo/v2 v2.8.1
github.com/onsi/gomega v1.26.0
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.25.0
k8s.io/apiextensions-apiserver v0.25.0
k8s.io/apimachinery v0.25.0
k8s.io/client-go v0.25.0
k8s.io/klog/v2 v2.70.1
sigs.k8s.io/controller-runtime v0.13.0
)

require (
cloud.google.com/go/compute v1.6.1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand All @@ -33,13 +28,11 @@ require (
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
Expand Down Expand Up @@ -73,7 +66,6 @@ require (
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.5.0 // indirect
Expand All @@ -86,8 +78,8 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.25.0 // indirect
k8s.io/component-base v0.25.0 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
Expand Down
187 changes: 3 additions & 184 deletions go.sum

Large diffs are not rendered by default.

11 changes: 2 additions & 9 deletions pkg/apis/starrocks/v1/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,12 @@ package v1
const (
// ComponentLabelKey is Kubernetes recommended label key, it represents the component within the architecture
ComponentLabelKey string = "app.kubernetes.io/component"
// NameLabelKey is Kubernetes recommended label key, it represents the name of the application
NameLabelKey string = "app.kubernetes.io/name"

// OwnerReference list object depended by this object
// OwnerReference represents owner of the object
OwnerReference string = "app.starrocks.ownerreference/name"

// ComponentsResourceHash the component hash
// ComponentResourceHash the component hash
ComponentResourceHash string = "app.starrocks.components/hash"

ComponentReplicasEmpty string = "app.starrocks.components/replica/empty"

// ComponentGeneration record for last update generation for compare with new spec.
// ComponentGeneration string = "app.starrocks.components/generation"
)

// the labels value. default statefulset name
Expand Down
24 changes: 12 additions & 12 deletions pkg/common/resource_utils/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ type hashStatefulsetObject struct {
}

// StatefulsetHashObject construct the hash spec for deep equals to exist statefulset.
func statefulSetHashObject(st *appv1.StatefulSet, excludeReplica bool) hashStatefulsetObject {
func statefulSetHashObject(sts *appv1.StatefulSet, excludeReplica bool) hashStatefulsetObject {
// set -1 for the initial is zero.
replicas := int32(-1)
if !excludeReplica {
if st.Spec.Replicas != nil {
replicas = *st.Spec.Replicas
if sts.Spec.Replicas != nil {
replicas = *sts.Spec.Replicas
}
}
selector := metav1.LabelSelector{}
if st.Spec.Selector != nil {
selector = *st.Spec.Selector
if sts.Spec.Selector != nil {
selector = *sts.Spec.Selector
}

return hashStatefulsetObject{
name: st.Name,
namespace: st.Namespace,
labels: st.Labels,
finalizers: st.Finalizers,
name: sts.Name,
namespace: sts.Namespace,
labels: sts.Labels,
finalizers: sts.Finalizers,
selector: selector,
podTemplate: st.Spec.Template,
serviceName: st.Spec.ServiceName,
volumeClaimTemplates: st.Spec.VolumeClaimTemplates,
podTemplate: sts.Spec.Template,
serviceName: sts.Spec.ServiceName,
volumeClaimTemplates: sts.Spec.VolumeClaimTemplates,
replicas: replicas,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//go:build !providerless
// +build !providerless

/*
Copyright 2016 The Kubernetes Authors.
Copyright 2021-present, StarRocks Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -17,11 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package auth
package fake

import (
// Initialize client auth plugins for cloud providers.
_ "k8s.io/client-go/plugin/pkg/client/auth/azure"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/client-go/plugin/pkg/client/auth/openstack"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

// NewFakeClient creates a new fake Kubernetes client.
func NewFakeClient(scheme *runtime.Scheme, initObjs ...runtime.Object) client.Client {
return fake.NewClientBuilder().WithRuntimeObjects(initObjs...).WithScheme(scheme).Build()
}
99 changes: 0 additions & 99 deletions pkg/k8sutils/fake/fake_k8s_client.go

This file was deleted.

Loading

0 comments on commit 4c6d5dc

Please sign in to comment.