-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Autogenerate k8s manifests in skaffold init #3703
Conversation
Codecov Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems to me that when generating manifests, the "unable to automatically resolve builder/image pairs; run 'skaffold init' without '--force' to manually resolve ambiguities
" error path shouldn't even be exercised...there is nothing to match up!!! It is not the force that's broken -- I think this PR should contain the logic that when there is manifest generation, we know the pairing... especially the microservices case, when all the docker images are known and matched with exactly one manifest. but maybe I'm missing something.
@balopat the reason I left the commented out test in there is because we currently conflate two concepts in one flag:
clearly we don't want to support the first concept here if we're generating manifests, but we need to support the second concept to run the tests that actually call I agree we should fix these flags, but I don't think that should happen in this PR. |
return nil | ||
} | ||
|
||
func getGeneratedBuilderPair(b InitBuilder) GeneratedBuilderImagePair { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some tests for this method?
filepath.Dir()
will return all but last component meaning it will contain \
, .
which are not valid image name chars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is implicitly tested through TestResolveBuilderImages
and TestAutoSelectBuilders
. because of the way we detect builders in the analyze
step of the initializer, the last 5 cases in your linked snippet will never happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this true.
I run checked out your branch and ran into this issue
Project tree:
examples/getting-started <say this is root of the repo>
|__app
|__ deploy
|---- Dockerfile
|- main.go
Currently, the code assumes you are running skaffold init
from inside examples/app
. This logic is very sensitive to run context.
tejaldesai@@helm-deployment (init-k8sgen)$ ../../out/skaffold init --XXenableManifestGeneration
adding manifest path app/deploy/deployment.yaml for image app/deploy
apiVersion: skaffold/v2alpha4
kind: Config
metadata:
name: helm-deployment
deploy:
kubectl:
manifests:
- app/deploy/deployment.yaml
app/deploy/deployment.yaml - apiVersion: v1
kind: Service
metadata:
name: app/deploy
labels:
app: app/deploy
spec:
clusterIP: None
selector:
app: app/deploy
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app/deploy
labels:
app: app/deploy
spec:
replicas: 1
selector:
matchLabels:
app: app/deploy
template:
metadata:
labels:
app: app/deploy
spec:
containers:
- name: app/deploy
image: app/deploy
Do you want to write this configuration, along with the generated k8s manifests, to skaffold.yaml? [y/n]: y
Generated manifest app/deploy/deployment.yaml was written
Configuration skaffold.yaml was written
You can now run [skaffold build] to build the artifacts
or [skaffold run] to build and deploy
or [skaffold dev] to enter development mode, with auto-redeploy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I dug into this one more, and skaffold init
actually doesn't even work with this directory structure :/
i'm going to add sanitization to this PR, and open an issue to fix this separately.
6c5d54c
to
ec97f6c
Compare
@dgageot I'm going to add sanitization for the generated image name since it can contain illegal characters and then this should be good to go in |
Thanks for the explanation. I'm okay to go forward with this. |
NOTE: this feature is hidden behind a feature flag,
--XXenableManifestGeneration
, to allow for further iteration and improvement before exposing publicly.this change adds support for autogenerating k8s manifests in
skaffold init
for projects that do not have any. skaffold will generate a k8s yaml for each found image that is not referenced by an existing k8s yaml in the project directory, and each generated yaml file will contain a deployment for the image, and a service exposing the deployment.in the event that
skaffold init
finds a builder configuration in a project directory, but no k8s yaml referencing this image, we don't actually have any name for the image, so skaffold will generate a name. this name will either be:the name of the encompassing directory, in the event that the builder is found in a nested directory; or,
the name of the builder file itself, in the event that only one builder configuration is found
for each image, a yaml file will be generated containing kubernetes resource definitions for a service and a deployment. this file will either be:
<directory_name>/deployment.yaml
, for each builder that is found in a nested directory; or,<image_name>-deployment.yaml
, if we only have one builder configuration foundso for the
microservices
example, we would generatewhereas for the getting-started example, we would generate
Future Work