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

Support Deployment generation with kube generate #17950

Merged
merged 1 commit into from
Apr 3, 2023

Conversation

umohnani8
Copy link
Member

@umohnani8 umohnani8 commented Mar 27, 2023

The podman kube generate command can now generate a
Deployment kind when the --type flag is set to deployment.
By default, a Pod spec will be generated if --type flag is
not set.
Add --replicas flag to kube generate to allow users to set
the value of replicas in the generated yaml when generating a
Deployment kind.
Add e2e and minikube tests for this feature.

Fixes #17712

Signed-off-by: Urvashi Mohnani [email protected]

Does this PR introduce a user-facing change?

Add support to generate k8s Deployment kind with podman kube generate.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 27, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: umohnani8

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 27, 2023
@github-actions github-actions bot added the kind/api-change Change to remote API; merits scrutiny label Mar 27, 2023
@umohnani8
Copy link
Member Author

Deployment generation examples.

For a pod:

047f2c095796b37c29dff7bf7c106dd03bbfea00a0d25a2fb4c41a0bcdca9bf0
➜  podman git:(deployments) ✗ ./bin/podman create --pod  mypod alpine top
4ecac58b0ea6453c2a5246987e14de96284c0f1c8edda24d3b098adee3f052a0
➜  podman git:(deployments) ✗ ./bin/podman kube generate --type deployment --replicas 3 mypod
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-4.5.0-dev
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: "2023-03-27T21:14:12Z"
  labels:
    app: mypod
  name: mypod-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: mypod
  template:
    metadata:
      creationTimestamp: "2023-03-27T21:14:12Z"
      labels:
        app: mypod
      name: mypod
    spec:
      containers:
      - command:
        - top
        image: docker.io/library/alpine:latest
        name: ecstatichertz
      hostname: mypod```

For a container:
```➜  podman git:(deployments) ✗ ./bin/podman create alpine sleep 100
3e13d4780ed884f86e99eb5bd7335044770aa68c231987bb0da3a5940896458a
➜  podman git:(deployments) ✗ ./bin/podman kube generate --type deployment 3e13d4780ed8 
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-4.5.0-dev
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: "2023-03-27T21:15:33Z"
  labels:
    app: upbeatardinghelli-pod
  name: upbeatardinghelli-pod-deployment
spec:
  selector:
    matchLabels:
      app: upbeatardinghelli-pod
  template:
    metadata:
      annotations:
        io.podman.annotations.ulimit: nofile=524288:524288,nproc=127332:127332
      creationTimestamp: "2023-03-27T21:15:33Z"
      labels:
        app: upbeatardinghelli-pod
      name: upbeatardinghelli-pod
    spec:
      containers:
      - command:
        - sleep
        - "100"
        image: docker.io/library/alpine:latest
        name: upbeatardinghelli```

@TomSweeneyRedHat
Copy link
Member

All kinds of test unhappiness @umohnani8

@umohnani8 umohnani8 force-pushed the deployments branch 7 times, most recently from a06505e to 678b71b Compare March 30, 2023 20:05
@umohnani8
Copy link
Member Author

Tests are mostly green! @containers/podman-maintainers PTAL

@mheon
Copy link
Member

mheon commented Mar 31, 2023

Will review tomorrow morning.

@containers/podman-maintainers PTAL

pkg/bindings/generate/generate.go Outdated Show resolved Hide resolved
cmd/podman/kube/generate.go Outdated Show resolved Hide resolved
libpod/define/container.go Outdated Show resolved Hide resolved
libpod/kube.go Show resolved Hide resolved
cmd/podman/kube/generate.go Outdated Show resolved Hide resolved
@umohnani8 umohnani8 force-pushed the deployments branch 4 times, most recently from a115e75 to ece9e86 Compare March 31, 2023 17:03
The podman kube generate command can now generate a
Deployment kind when the --ype flag is set to deployment.
By default, a Pod spec will be generated if --type flag is
not set.
Add --replicas flag to kube generate to allow users to set
the value of replicas in the generated yaml when generating a
Deployment kind.
Add e2e and minikube tests for this feature.

Signed-off-by: Urvashi Mohnani <[email protected]>
@ashley-cui
Copy link
Member

ashley-cui commented Mar 31, 2023

LGTM, thanks for getting this out so fast :)

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Let's wait for a head nod from @edsantiago for the tests.

Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough about minikube to review the e2e or minikube tests. One question in system tests, otherwise LGTM

@@ -106,24 +106,23 @@ metadata.labels.app | = | ${pname}
metadata.name | = | ${pname}

spec.hostname | = | $pname
spec.restartPolicy | = | Never
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason not to change this one from Never to null, like the others? Why are you removing this check entirely?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restartPolicy will not be a field in the generated yaml for the default case. I don't think null would be a valid value here as it isn't a pointer as the others are.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can open another PR to test that out, but would like to get this one in today before we need to cut the release.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, thanks for the explanation. LGTM then.

@umohnani8
Copy link
Member Author

This is ready, please merge when possible @mheon @rhatdan @vrothberg @baude

@rhatdan
Copy link
Member

rhatdan commented Apr 3, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 3, 2023
@openshift-merge-robot openshift-merge-robot merged commit 9893345 into containers:main Apr 3, 2023
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 3, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/api-change Change to remote API; merits scrutiny lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Be able to generate Deployment with podman generate kube
9 participants