diff --git a/pkg/modules/generators/app_configurations_generator.go b/pkg/modules/generators/app_configurations_generator.go index 5e33af83..317e729d 100644 --- a/pkg/modules/generators/app_configurations_generator.go +++ b/pkg/modules/generators/app_configurations_generator.go @@ -26,6 +26,7 @@ import ( "gopkg.in/yaml.v3" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" + k8sjson "k8s.io/apimachinery/pkg/util/json" "kcl-lang.io/kpm/pkg/package" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" @@ -214,7 +215,17 @@ func PatchWorkload(workload *v1.Resource, patcher *v1.Patcher) error { } un := &unstructured.Unstructured{} - un.SetUnstructuredContent(workload.Attributes) + attributes := workload.Attributes + + // normalize attributes with K8s json util. Especially numbers are converted to int64 or float64 + out, err := k8sjson.Marshal(attributes) + if err != nil { + return err + } + if err = k8sjson.Unmarshal(out, &attributes); err != nil { + return err + } + un.SetUnstructuredContent(attributes) // patch labels if patcher.Labels != nil { diff --git a/pkg/modules/generators/app_configurations_generator_test.go b/pkg/modules/generators/app_configurations_generator_test.go index 9fac6a9c..25f66e78 100644 --- a/pkg/modules/generators/app_configurations_generator_test.go +++ b/pkg/modules/generators/app_configurations_generator_test.go @@ -8,6 +8,7 @@ import ( "github.com/bytedance/mockey" "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v3" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -292,6 +293,14 @@ func Test_patchWorkload(t *testing.T) { { Name: "my-app", Image: "my-app-image", + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Host: "localhost:8080", + }, + }, + InitialDelaySeconds: 2, + }, Env: []corev1.EnvVar{ { Name: "MY_ENV", @@ -304,8 +313,14 @@ func Test_patchWorkload(t *testing.T) { }, }, } - // convert deploy to unstructured + + // convert deploy to map with yamlv3 to simulate what we did in the module framework deploymentUnstructured, err := runtime.DefaultUnstructuredConverter.ToUnstructured(deployment) + assert.NoError(t, err) + out, err := yaml.Marshal(deploymentUnstructured) + assert.NoError(t, err) + err = yaml.Unmarshal(out, deploymentUnstructured) + res := &v1.Resource{ ID: "apps/v1:Deployment:default:default-dev-foo", Type: "Kubernetes",