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

Option to output conversion to one file. #1539

Closed
cdrage opened this issue Nov 21, 2022 · 10 comments
Closed

Option to output conversion to one file. #1539

cdrage opened this issue Nov 21, 2022 · 10 comments
Assignees

Comments

@cdrage
Copy link
Member

cdrage commented Nov 21, 2022

Similar to helm and other k8s tools, we should be able to have the option to output to one file, rather than multiple files.

Or maybe we should make it the default that everything is outputted to one file? What do people think?

@OneCricketeer
Copy link

IMO, --one-file flag would be helpful only for saving that output file to some location without a loop to do the same...

kubectl apply can accept a directory of files, right? So, why need to combine?

I've always used kompose to get a rough idea of what I need to do. Then I convert to Charts, as I see fit.

@AhmedGrati
Copy link
Contributor

@OneCricketeer For debugging purposes, you might occasionally need to display all the manifests in one file so that you don't have to switch between them when a problem arises. Therefore, IMO I see that the default behavior should remain the same, and we add the --one-file flag to save the output in one file.

@AhmedGrati
Copy link
Contributor

After investigating this issue, I found that this functionality already exists, by using the --file flag. For example:

kompose convert -f docker-compose.yaml --out f.yaml

But the issue is that the output is not the correct one. In fact, for this docker-compose file:

version: "3.8"

services:
  front_end:
    image: gcr.io/google-samples/gb-frontend:v4
    ports:
      - "80:80"
    environment:
      - GET_HOSTS_FROM=dns
    labels:
      kompose.service.expose: lb
      kompose.service.expose.ingress-class-name: nginx

we'll have the following output:

apiVersion: v1
items:
  - apiVersion: v1
    kind: Service
    metadata:
      annotations:
        kompose.cmd: /var/folders/jn/kphqd_553871ydfcs_2_5kbm0000gn/T/go-build1291552472/b001/exe/main convert -f docker-compose.yaml --out f.yaml
        kompose.service.expose: lb
        kompose.service.expose.ingress-class-name: nginx
        kompose.version: 1.26.1 (HEAD)
      creationTimestamp: null
      labels:
        io.kompose.service: front-end
      name: front_end
    spec:
      ports:
        - name: "80"
          port: 80
          targetPort: 80
      selector:
        io.kompose.service: front-end
    status:
      loadBalancer: {}
  - apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        kompose.cmd: /var/folders/jn/kphqd_553871ydfcs_2_5kbm0000gn/T/go-build1291552472/b001/exe/main convert -f docker-compose.yaml --out f.yaml
        kompose.service.expose: lb
        kompose.service.expose.ingress-class-name: nginx
        kompose.version: 1.26.1 (HEAD)
      creationTimestamp: null
      labels:
        io.kompose.service: front-end
      name: front-end
    spec:
      replicas: 1
      selector:
        matchLabels:
          io.kompose.service: front-end
      strategy: {}
      template:
        metadata:
          annotations:
            kompose.cmd: /var/folders/jn/kphqd_553871ydfcs_2_5kbm0000gn/T/go-build1291552472/b001/exe/main convert -f docker-compose.yaml --out f.yaml
            kompose.service.expose: lb
            kompose.service.expose.ingress-class-name: nginx
            kompose.version: 1.26.1 (HEAD)
          creationTimestamp: null
          labels:
            io.kompose.service: front-end
        spec:
          containers:
            - env:
                - name: GET_HOSTS_FROM
                  value: dns
              image: gcr.io/google-samples/gb-frontend:v4
              name: front-end
              ports:
                - containerPort: 80
              resources: {}
          restartPolicy: Always
    status: {}
  - apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      annotations:
        kompose.cmd: /var/folders/jn/kphqd_553871ydfcs_2_5kbm0000gn/T/go-build1291552472/b001/exe/main convert -f docker-compose.yaml --out f.yaml
        kompose.service.expose: lb
        kompose.service.expose.ingress-class-name: nginx
        kompose.version: 1.26.1 (HEAD)
      creationTimestamp: null
      labels:
        io.kompose.service: front-end
      name: front-end
    spec:
      ingressClassName: nginx
      rules:
        - host: lb
          http:
            paths:
              - backend:
                  service:
                    name: front-end
                    port:
                      number: 80
                path: /
                pathType: Prefix
    status:
      loadBalancer: {}
kind: List
metadata: {}

As you can see, the output file is not in the desired behavior, because we cannot use it directly by kubectl. What do you think @cdrage @hangyan?

@hangyan
Copy link
Contributor

hangyan commented Nov 24, 2022

Yeah, we support that. But what do you mean by 'cannot use it diectly'?

@AhmedGrati
Copy link
Contributor

AhmedGrati commented Nov 24, 2022

Yeah, we support that. But what do you mean by 'cannot use it diectly'?

I mean that we cannot execute kubectl apply on that file.

@cdrage
Copy link
Member Author

cdrage commented Nov 24, 2022

After investigating this issue, I found that this functionality already exists, by using the --file flag. For example:

kompose convert -f docker-compose.yaml --out f.yaml

But the issue is that the output is not the correct one. In fact, for this docker-compose file:

version: "3.8"

services:
  front_end:
    image: gcr.io/google-samples/gb-frontend:v4
    ports:
      - "80:80"
    environment:
      - GET_HOSTS_FROM=dns
    labels:
      kompose.service.expose: lb
      kompose.service.expose.ingress-class-name: nginx

we'll have the following output:

apiVersion: v1
items:
  - apiVersion: v1
    kind: Service
    metadata:
      annotations:
        kompose.cmd: /var/folders/jn/kphqd_553871ydfcs_2_5kbm0000gn/T/go-build1291552472/b001/exe/main convert -f docker-compose.yaml --out f.yaml
        kompose.service.expose: lb
        kompose.service.expose.ingress-class-name: nginx
        kompose.version: 1.26.1 (HEAD)
      creationTimestamp: null
      labels:
        io.kompose.service: front-end
      name: front_end
    spec:
      ports:
        - name: "80"
          port: 80
          targetPort: 80
      selector:
        io.kompose.service: front-end
    status:
      loadBalancer: {}
  - apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        kompose.cmd: /var/folders/jn/kphqd_553871ydfcs_2_5kbm0000gn/T/go-build1291552472/b001/exe/main convert -f docker-compose.yaml --out f.yaml
        kompose.service.expose: lb
        kompose.service.expose.ingress-class-name: nginx
        kompose.version: 1.26.1 (HEAD)
      creationTimestamp: null
      labels:
        io.kompose.service: front-end
      name: front-end
    spec:
      replicas: 1
      selector:
        matchLabels:
          io.kompose.service: front-end
      strategy: {}
      template:
        metadata:
          annotations:
            kompose.cmd: /var/folders/jn/kphqd_553871ydfcs_2_5kbm0000gn/T/go-build1291552472/b001/exe/main convert -f docker-compose.yaml --out f.yaml
            kompose.service.expose: lb
            kompose.service.expose.ingress-class-name: nginx
            kompose.version: 1.26.1 (HEAD)
          creationTimestamp: null
          labels:
            io.kompose.service: front-end
        spec:
          containers:
            - env:
                - name: GET_HOSTS_FROM
                  value: dns
              image: gcr.io/google-samples/gb-frontend:v4
              name: front-end
              ports:
                - containerPort: 80
              resources: {}
          restartPolicy: Always
    status: {}
  - apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      annotations:
        kompose.cmd: /var/folders/jn/kphqd_553871ydfcs_2_5kbm0000gn/T/go-build1291552472/b001/exe/main convert -f docker-compose.yaml --out f.yaml
        kompose.service.expose: lb
        kompose.service.expose.ingress-class-name: nginx
        kompose.version: 1.26.1 (HEAD)
      creationTimestamp: null
      labels:
        io.kompose.service: front-end
      name: front-end
    spec:
      ingressClassName: nginx
      rules:
        - host: lb
          http:
            paths:
              - backend:
                  service:
                    name: front-end
                    port:
                      number: 80
                path: /
                pathType: Prefix
    status:
      loadBalancer: {}
kind: List
metadata: {}

As you can see, the output file is not in the desired behavior, because we cannot use it directly by kubectl. What do you think @cdrage @hangyan?

Yeah, we shouldn't be using List.

With Helm, you can export it and it just adds --- between each kind / section.

We should do the same with Kompose. You should be able to generate a single file using --- between each section.

@hangyan
Copy link
Contributor

hangyan commented Nov 25, 2022

Agreed. --- is the best approach to do this.(i thought List can be applied before...)

@AhmedGrati
Copy link
Contributor

/assign

@AhmedGrati
Copy link
Contributor

Mark this as closed, solved by #1541.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants