diff --git a/api/handler/resource.go b/api/handler/resource.go index d91779c3c2..6339812b21 100644 --- a/api/handler/resource.go +++ b/api/handler/resource.go @@ -17,11 +17,12 @@ import ( yamlt "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/client-go/dynamic" "k8s.io/client-go/restmapper" + "strings" ) // AddAppK8SResource - func (c *clusterAction) AddAppK8SResource(ctx context.Context, namespace string, appID string, resourceYaml string) ([]*dbmodel.K8sResource, *util.APIHandleError) { - resourceObjects := c.HandleResourceYaml([]byte(resourceYaml), namespace, "create", "", map[string]string{"app_id": appID}) + resourceObjects := c.HandleResourceYaml([]byte(strings.TrimPrefix(resourceYaml, "\n")), namespace, "create", "", map[string]string{"app_id": appID}) var resourceList []*dbmodel.K8sResource for _, resourceObject := range resourceObjects { resource := resourceObject diff --git a/api/handler/yaml_resource.go b/api/handler/yaml_resource.go index a70dfc160e..169e3af21a 100644 --- a/api/handler/yaml_resource.go +++ b/api/handler/yaml_resource.go @@ -357,11 +357,12 @@ func (c *clusterAction) YamlToResource(yamlResource api_model.YamlResource, yaml var fileBuildResourceList []api_model.K8sResourceObject for _, yamlFilePath := range yamlFilesPath { var fileName string - yamlFileBytes := []byte(yamlContent) + yamlFileBytes := []byte(strings.TrimPrefix(yamlContent, "\n")) if yamlSource == api_model.YamlSourceFile { fileName = path.Base(yamlFilePath) var err error yamlFileBytes, err = ioutil.ReadFile(yamlFilePath) + yamlFileBytes = []byte(strings.TrimPrefix(string(yamlFileBytes), "\n")) if err != nil { logrus.Errorf("%v", err) fileBuildResourceList = append(fileBuildResourceList, api_model.K8sResourceObject{ diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index eb0d27eb20..c96c497e1c 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -194,7 +194,11 @@ func (h *Helm) install(name, chart, version string, overrides []string, dryRun b if err != nil { return nil, err } - + var crdYaml string + crds := chartRequested.CRDObjects() + for _, crd := range crds { + crdYaml += string(crd.File.Data) + } if err := checkIfInstallable(chartRequested); err != nil { return nil, err } @@ -231,8 +235,9 @@ func (h *Helm) install(name, chart, version string, overrides []string, dryRun b } } } - - return client.Run(chartRequested, vals) + rel, err := client.Run(chartRequested, vals) + rel.Manifest = strings.TrimPrefix(crdYaml+"\n"+rel.Manifest, "\n") + return rel, err } func (h *Helm) parseOverrides(overrides []string) (map[string]interface{}, error) {