Skip to content

Commit

Permalink
chore: update PodSet defaulter
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberchen98 committed Jun 28, 2024
1 parent 285ef3c commit ff4718d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions pkg/webhook/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ func validatePodSet(podSet *v1alpha1.PodSet, path *field.Path) field.ErrorList {
errs = append(errs, field.Invalid(path.Child("semanticVersion"), *podSet.SemanticVersion, err.Error()))
}
}

if podSet.ExportToPrometheus != nil && *podSet.ExportToPrometheus {
promDiscoveryScheme := path.Child("promDiscoveryScheme")
if podSet.PromDiscoveryScheme == nil {
errs = append(errs, field.Invalid(path.Child("promDiscoveryScheme"), "", "ExportToPrometheus is enabled but PromDiscoveryScheme is not provided"))
errs = append(errs, field.Invalid(promDiscoveryScheme, "", "ExportToPrometheus is enabled but PromDiscoveryScheme is not provided"))
} else if *podSet.PromDiscoveryScheme != v1alpha1.PromDiscoverySchemePod && *podSet.PromDiscoveryScheme != v1alpha1.PromDiscoverySchemeService {
errs = append(errs, field.Invalid(path.Child("promDiscoveryScheme"), *podSet.PromDiscoveryScheme,
errs = append(errs, field.Invalid(promDiscoveryScheme, *podSet.PromDiscoveryScheme,
fmt.Sprintf("invalid PromDiscoveryScheme, must be %s or %s", v1alpha1.PromDiscoverySchemePod, v1alpha1.PromDiscoverySchemeService)))
}
}
Expand Down
11 changes: 8 additions & 3 deletions pkg/webhook/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ package webhook

import (
"fmt"

"github.com/go-errors/errors"
"github.com/matrixorigin/matrixone-operator/api/core/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"

"github.com/matrixorigin/matrixone-operator/api/core/v1alpha1"
"k8s.io/utils/pointer"
)

// DefaultArgs alias to v1alpha1.DefaultArgs
Expand Down Expand Up @@ -65,6 +64,12 @@ func setPodSetDefaults(s *v1alpha1.PodSet) {
s.Overlay.Env = appendIfNotExist(s.Overlay.Env, corev1.EnvVar{Name: v1alpha1.EnvGoDebug, Value: v1alpha1.DefaultGODebug}, func(v corev1.EnvVar) string {
return v.Name
})

if s.ExportToPrometheus != nil && *s.ExportToPrometheus {
if s.PromDiscoveryScheme == nil {
s.PromDiscoveryScheme = (*v1alpha1.PromDiscoveryScheme)(pointer.String(string(v1alpha1.PromDiscoverySchemeService)))
}
}
}

func appendIfNotExist[K comparable, V any](list []V, elem V, keyFunc func(V) K) []V {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
recon "github.com/matrixorigin/controller-runtime/pkg/reconciler"
"github.com/matrixorigin/controller-runtime/pkg/util"
"github.com/matrixorigin/matrixone-operator/api/core/v1alpha1"
"github.com/matrixorigin/matrixone-operator/test/e2e/e2eminio"
e2eutil "github.com/matrixorigin/matrixone-operator/test/e2e/util"
Expand Down Expand Up @@ -105,7 +106,7 @@ var _ = Describe("Matrix BucketClaim test", func() {
It("Should bucket been deleted use delete retain policy", func() {
By("create logset cluster with minio provider")
minioSecret := e2eutil.MinioSecret(env.Namespace)
Expect(kubeCli.Create(ctx, minioSecret)).To(Succeed())
Expect(util.Ignore(apierrors.IsAlreadyExists, kubeCli.Create(ctx, minioSecret))).To(Succeed())

minioProvider := e2eutil.MinioShareStorage(minioSecret.Name)
policyDelete := v1alpha1.PVCRetentionPolicyDelete
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/matrixonecluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ var _ = Describe("MatrixOneCluster test", func() {
By("Create cluster with maximum name length")
minioSecret := e2eutil.MinioSecret(env.Namespace)
minioProvider := e2eutil.MinioShareStorage(minioSecret.Name)
Expect(kubeCli.Create(context.TODO(), minioSecret)).To(Succeed())
Expect(util.Ignore(apierrors.IsAlreadyExists, kubeCli.Create(context.TODO(), minioSecret))).To(Succeed())
maxLengthName := strings.Repeat("a", mowebhook.MatrixOneClusterNameMaxLength)
mo := &v1alpha1.MatrixOneCluster{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit ff4718d

Please sign in to comment.