Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup the APIs pkg deps and keep them compact #8244

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions apis/extensions/v1alpha1/addon_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"

"github.com/apecloud/kubeblocks/pkg/testutil"
)

func TestSelectorRequirementString(t *testing.T) {
Expand All @@ -50,7 +48,7 @@ func TestSelectorRequirementNoOperator(t *testing.T) {
func TestSelectorRequirementContains(t *testing.T) {
g := NewGomegaWithT(t)
const distro = "k3s"
testutil.SetKubeServerVersionWithDistro("1", "24", "0", distro)
SetKubeServerVersionWithDistro("1", "24", "0", distro)
r := SelectorRequirement{
Key: KubeGitVersion,
Operator: Contains,
Expand Down Expand Up @@ -83,7 +81,7 @@ func TestSelectorRequirementContains(t *testing.T) {
func TestSelectorRequirementNotContains(t *testing.T) {
g := NewGomegaWithT(t)
const distro = "k3s"
testutil.SetKubeServerVersionWithDistro("1", "24", "0", distro)
SetKubeServerVersionWithDistro("1", "24", "0", distro)
r := SelectorRequirement{
Key: KubeGitVersion,
Operator: DoesNotContain,
Expand Down Expand Up @@ -115,7 +113,7 @@ func TestSelectorRequirementNotContains(t *testing.T) {
func TestSelectorRequirementMatchRegex(t *testing.T) {
g := NewGomegaWithT(t)
const distro = "k3s"
testutil.SetKubeServerVersionWithDistro("1", "24", "0", distro)
SetKubeServerVersionWithDistro("1", "24", "0", distro)
r := SelectorRequirement{
Key: KubeGitVersion,
Operator: MatchRegex,
Expand Down Expand Up @@ -150,7 +148,7 @@ func TestSelectorRequirementMatchRegex(t *testing.T) {
"^v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
}
g.Expect(r.MatchesFromConfig()).Should(BeTrue())
testutil.SetKubeServerVersion("1", "24", "0")
SetKubeServerVersion("1", "24", "0")
g.Expect(r.MatchesFromConfig()).Should(BeTrue())

// pass KubeVersion
Expand All @@ -171,7 +169,7 @@ func TestSelectorRequirementMatchRegex(t *testing.T) {
func TestSelectorRequirementNotMatchRegex(t *testing.T) {
g := NewGomegaWithT(t)
const distro = "k3s"
testutil.SetKubeServerVersionWithDistro("1", "24", "0", distro)
SetKubeServerVersionWithDistro("1", "24", "0", distro)
r := SelectorRequirement{
Key: KubeGitVersion,
Operator: DoesNotMatchRegex,
Expand Down
29 changes: 29 additions & 0 deletions apis/extensions/v1alpha1/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ limitations under the License.

package v1alpha1

import (
"fmt"

"k8s.io/apimachinery/pkg/version"

"github.com/apecloud/kubeblocks/pkg/constant"
viper "github.com/apecloud/kubeblocks/pkg/viperx"
)

// AddonType defines the addon types.
// +enum
// +kubebuilder:validation:Enum={Helm}
Expand Down Expand Up @@ -67,3 +76,23 @@ const (
ConditionTypeSucceed = "Succeed"
ConditionTypeFailed = "Failed"
)

// SetKubeServerVersion provides "_KUBE_SERVER_INFO" viper settings helper function.
func SetKubeServerVersion(major, minor, patch string) {
ver := version.Info{
Major: major,
Minor: minor,
GitVersion: fmt.Sprintf("v%s.%s.%s", major, minor, patch),
}
viper.Set(constant.CfgKeyServerInfo, ver)
}

// SetKubeServerVersionWithDistro provides "_KUBE_SERVER_INFO" viper settings helper function.
func SetKubeServerVersionWithDistro(major, minor, patch, distro string) {
ver := version.Info{
Major: major,
Minor: minor,
GitVersion: fmt.Sprintf("v%s.%s.%s+%s", major, minor, patch, distro),
}
viper.Set(constant.CfgKeyServerInfo, ver)
}
3 changes: 1 addition & 2 deletions controllers/extensions/addon_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import (
extensionsv1alpha1 "github.com/apecloud/kubeblocks/apis/extensions/v1alpha1"
"github.com/apecloud/kubeblocks/pkg/constant"
"github.com/apecloud/kubeblocks/pkg/generics"
"github.com/apecloud/kubeblocks/pkg/testutil"
testapps "github.com/apecloud/kubeblocks/pkg/testutil/apps"
viper "github.com/apecloud/kubeblocks/pkg/viperx"
)
Expand Down Expand Up @@ -104,7 +103,7 @@ var _ = Describe("Addon controller", func() {
BeforeEach(func() {
cleanEnv()
const distro = "kubeblocks"
testutil.SetKubeServerVersionWithDistro("1", "24", "0", distro)
extensionsv1alpha1.SetKubeServerVersionWithDistro("1", "24", "0", distro)
Expect(client.IgnoreAlreadyExists(testCtx.CreateNamespace())).To(Not(HaveOccurred()))
})

Expand Down
23 changes: 0 additions & 23 deletions pkg/testutil/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package testutil

import (
"context"
"fmt"
"os"
"time"

Expand All @@ -30,11 +29,9 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/version"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"

"github.com/apecloud/kubeblocks/pkg/constant"
viper "github.com/apecloud/kubeblocks/pkg/viperx"
)

Expand Down Expand Up @@ -184,23 +181,3 @@ func (testCtx TestContext) UseDefaultNamespace() func(client.Object) {
obj.SetNamespace(testCtx.DefaultNamespace)
}
}

// SetKubeServerVersionWithDistro provides "_KUBE_SERVER_INFO" viper settings helper function.
func SetKubeServerVersionWithDistro(major, minor, patch, distro string) {
ver := version.Info{
Major: major,
Minor: minor,
GitVersion: fmt.Sprintf("v%s.%s.%s+%s", major, minor, patch, distro),
}
viper.Set(constant.CfgKeyServerInfo, ver)
}

// SetKubeServerVersion provides "_KUBE_SERVER_INFO" viper settings helper function.
func SetKubeServerVersion(major, minor, patch string) {
ver := version.Info{
Major: major,
Minor: minor,
GitVersion: fmt.Sprintf("v%s.%s.%s", major, minor, patch),
}
viper.Set(constant.CfgKeyServerInfo, ver)
}
Loading