Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kargo Render should ignore contents of configmap when rendering #278

Open
jimil749 opened this issue Apr 17, 2024 · 3 comments
Open

Kargo Render should ignore contents of configmap when rendering #278

jimil749 opened this issue Apr 17, 2024 · 3 comments
Labels
good first issue Good issue for a new contributor to handle help-wanted Community help on this would be appreciated kind/bug priority/normal

Comments

@jimil749
Copy link

jimil749 commented Apr 17, 2024

I am trying to render manifest for apache airflow (by using kustomize + upstream helm charts). It includes a configmap manifest which looks like following:

apiVersion: v1
data:
  mappings.yml: |-
    # Licensed to the Apache Software Foundation (ASF) under one
    # or more contributor license agreements.  See the NOTICE file
    # distributed with this work for additional information
    # regarding copyright ownership.  The ASF licenses this file
    # to you under the Apache License, Version 2.0 (the
    # "License"); you may not use this file except in compliance
    # with the License.  You may obtain a copy of the License at
    #
    #   http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing,
    # software distributed under the License is distributed on an
    # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    # KIND, either express or implied.  See the License for the
    # specific language governing permissions and limitations
    # under the License.
    ---
    mappings:
     ...
kind: ConfigMap
metadata:
  labels:
    chart: airflow-1.11.0
    component: config
    heritage: Helm
    release: airflow
    tier: airflow
  name: airflow-statsd

This breaks the render with the following error:

level=fatal msg="error writing manifests for app \"airflow\" to \"/tmp/2142585927/repo/airflow\": resource is missing kind field"

This is because of "---" in the configmap data. Render splits the above manifest into 2 parts (since it uses "---" as the separator) which cause the render to fail.

Render would work fine if it is possible to just ignore the contents of cm.

@krancour
Copy link
Member

@jimil749 I assume you don't mean that the contents of a cm shouldn't be rendered. I assume you mean we should take greater care here to only split on --- if it appears at the beginning of a line?

func SplitYAML(manifest []byte) (map[string][]byte, error) {
manifests := bytes.Split(manifest, []byte("---\n"))
manifestsByResourceTypeAndName := map[string][]byte{}
for _, manifest = range manifests {
resource := struct {
Kind string `json:"kind"`
Metadata struct {
Name string `json:"name"`
} `json:"metadata"`
}{}
if err := yaml.Unmarshal(manifest, &resource); err != nil {
return nil, fmt.Errorf("error unmarshaling resource: %w", err)
}
if resource.Kind == "" {
return nil, errors.New("resource is missing kind field")
}
if resource.Metadata.Name == "" {
return nil, errors.New("resource is missing metadata.name field")
}
resourceTypeAndName := fmt.Sprintf(
"%s-%s",
strings.ToLower(resource.Metadata.Name),
strings.ToLower(resource.Kind),
)
manifestsByResourceTypeAndName[resourceTypeAndName] = manifest
}
return manifestsByResourceTypeAndName, nil
}

If that was your meaning, I agree.

@jimil749
Copy link
Author

@krancour exactly. Contents of a cm should be rendered but greater care needs to take to split on ---.

@krancour krancour added good first issue Good issue for a new contributor to handle help-wanted Community help on this would be appreciated priority/normal kind/bug and removed needs/kind needs/priority labels Apr 18, 2024
@benjamin-bergia
Copy link

This seems to be happening a quite a few charts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good issue for a new contributor to handle help-wanted Community help on this would be appreciated kind/bug priority/normal
Projects
None yet
Development

No branches or pull requests

3 participants