From 0af9f9b022b987033f85abebe93ecf71e2f6e2d2 Mon Sep 17 00:00:00 2001 From: cuisongliu Date: Thu, 3 Oct 2024 11:04:02 +0800 Subject: [PATCH] test(sealos): images fix Signed-off-by: cuisongliu --- Dockerfile | 4 ++-- api/v1beta1/automq_webhook.go | 4 +++- api/v1beta1/webhook_suite_test.go | 6 ++++-- api/v1beta1/zz_generated.deepcopy.go | 2 +- {api/v1beta1 => defaults}/images.go | 2 +- gen/gen.go | 4 ++-- 6 files changed, 13 insertions(+), 9 deletions(-) rename {api/v1beta1 => defaults}/images.go (97%) diff --git a/Dockerfile b/Dockerfile index 1e4f47c..0e3cb12 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,8 +14,8 @@ RUN go mod download # Copy the go source COPY cmd/main.go cmd/main.go COPY api/ api/ -COPY internal/controller/ internal/controller/ - +COPY internal/ internal/ +COPY defaults defaults # Build # the GOARCH has not a default value to allow the binary be built according to the host where the command # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO diff --git a/api/v1beta1/automq_webhook.go b/api/v1beta1/automq_webhook.go index dd97fb0..2fa493d 100644 --- a/api/v1beta1/automq_webhook.go +++ b/api/v1beta1/automq_webhook.go @@ -18,6 +18,8 @@ package v1beta1 import ( "fmt" + + "github.com/cuisongliu/automq-operator/defaults" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" logf "sigs.k8s.io/controller-runtime/pkg/log" @@ -42,7 +44,7 @@ var _ webhook.Defaulter = &AutoMQ{} func (r *AutoMQ) Default() { automqlog.Info("default", "name", r.Name) if r.Spec.Image == "" { - r.Spec.Image = DefaultImageName + r.Spec.Image = defaults.DefaultImageName } if r.Spec.S3.Region == "" { r.Spec.S3.Region = "us-east-1" diff --git a/api/v1beta1/webhook_suite_test.go b/api/v1beta1/webhook_suite_test.go index 223ecd5..22d2e41 100644 --- a/api/v1beta1/webhook_suite_test.go +++ b/api/v1beta1/webhook_suite_test.go @@ -20,13 +20,15 @@ import ( "context" "crypto/tls" "fmt" - "k8s.io/apimachinery/pkg/api/errors" "net" "path/filepath" "runtime" "testing" "time" + "github.com/cuisongliu/automq-operator/defaults" + "k8s.io/apimachinery/pkg/api/errors" + v1 "k8s.io/api/admissionregistration/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" @@ -89,7 +91,7 @@ var _ = Describe("Default", func() { Expect(err).To(BeNil()) err = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(aq), aq) Expect(err).To(BeNil()) - Expect(aq.Spec.Image).To(Equal(DefaultImageName)) + Expect(aq.Spec.Image).To(Equal(defaults.DefaultImageName)) }) It("Default Region", func() { aq := initAutoMQ() diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 980ebb9..313ad66 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -21,7 +21,7 @@ limitations under the License. package v1beta1 import ( - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" ) diff --git a/api/v1beta1/images.go b/defaults/images.go similarity index 97% rename from api/v1beta1/images.go rename to defaults/images.go index 8842e2d..9c6ffb0 100644 --- a/api/v1beta1/images.go +++ b/defaults/images.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1beta1 +package defaults const ( DefaultImageName = "automqinc/automq:1.2.0-rc1" diff --git a/gen/gen.go b/gen/gen.go index 82dc38f..dc89e1a 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -18,7 +18,7 @@ package main import ( "fmt" - "github.com/cuisongliu/automq-operator/api/v1beta1" + "github.com/cuisongliu/automq-operator/defaults" "os" "os/exec" "strings" @@ -32,7 +32,7 @@ func main() { imageName := os.Args[1] fmt.Printf("image name is %s", imageName) _ = os.MkdirAll("deploy/images/shim", 0755) - _ = os.WriteFile("deploy/images/shim/image.txt", []byte(v1beta1.DefaultImageName), 0755) + _ = os.WriteFile("deploy/images/shim/image.txt", []byte(defaults.DefaultImageName), 0755) cmd1 := fmt.Sprintf("sed -i '/#replace_by_makefile/!b;n;c\\image: %s' deploy/charts/automq-operator/values.yaml", imageName) if err := execCmd("bash", "-c", cmd1); err != nil { fmt.Printf("execCmd error %v", err)