Skip to content

Commit

Permalink
fix: helm install operator not create crd (#1556)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangSetSail committed Feb 17, 2023
1 parent 206129b commit 8e43ea5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion api/handler/resource.go
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion api/handler/yaml_resource.go
Expand Up @@ -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{
Expand Down
11 changes: 8 additions & 3 deletions pkg/helm/helm.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8e43ea5

Please sign in to comment.