-
Notifications
You must be signed in to change notification settings - Fork 40
feat(spec): add support for extraResources #173
Conversation
@surajssd, thank you for the pull request! We'll ping some people to review your PR. @containscafeine, please review this. |
TODO:
|
ebd5eaa
to
05b3bd3
Compare
api_v1 "k8s.io/client-go/pkg/api/v1" | ||
ext_v1beta1 "k8s.io/client-go/pkg/apis/extensions/v1beta1" | ||
"k8s.io/client-go/pkg/runtime" | ||
"k8s.io/client-go/pkg/util/intstr" |
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 happened according to this #149 (comment)
blocked on #172 |
05b3bd3
to
d9ecf79
Compare
e1e9dc0
to
b0006fe
Compare
since #172 is merged this is not blocked anymore and open to review |
ping: @containscafeine @kadel |
b0006fe
to
e198665
Compare
e198665
to
387e0e8
Compare
@containscafeine rebased! |
examples/extraResources/README.md
Outdated
Kedge might not support all the things that Kubernetes has, but kedge would not | ||
come in your way to define anything that Kubernetes understands. | ||
|
||
For e.g. right now there is no way to define secrets in kedge, but you can still |
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 think we can't remove those lines, as there is already is PR for secrets.
Some alpha features like CronJob might be better example
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.
changed the example.
@@ -334,7 +334,7 @@ func populateEnvFrom(app *spec.App) error { | |||
return nil | |||
} | |||
|
|||
func CreateK8sObjects(app *spec.App) ([]runtime.Object, error) { | |||
func CreateK8sObjects(app *spec.App) ([]runtime.Object, []string, error) { |
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 think that it would be good to add comment explaining what this does and what each return value is ([]runtime.Object
, []string
)
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.
done
} | ||
|
||
func Transform(app *spec.App) ([]runtime.Object, error) { | ||
func Transform(app *spec.App) ([]runtime.Object, []string, error) { |
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.
Same here as for CreateK8sObjects
return values of those function are getting more complicated and it would be good to have a comment explaining it.
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.
done
Just a few missing comments and doc fix, otherwise it looks good to me 👍 |
3f76f88
to
3c8b711
Compare
ping @containscafeine |
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.
will review code in a bit
docs/file-reference.md
Outdated
|
||
The file path are relative to the kedge application file. | ||
|
||
This is one of the mechanism to extend kedge beyond it's capabilites to support |
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.
one of the mechanisms
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.
s/it's/its
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.
done
examples/extraResources/README.md
Outdated
Kedge might not support all the things that Kubernetes has, but kedge would not | ||
come in your way to define anything that Kubernetes understands. | ||
|
||
For e.g. right now there is no way to define cron-jobs in kedge, but you can still |
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.
s/cron-jobs/Kubernetes cron jobs
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.
done
examples/extraResources/README.md
Outdated
come in your way to define anything that Kubernetes understands. | ||
|
||
For e.g. right now there is no way to define cron-jobs in kedge, but you can still | ||
specify the Kubernetes cron-job file. In this field called `extraResources`. |
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.
s/cron-job/cron job
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.
done
examples/extraResources/README.md
Outdated
``` | ||
|
||
So in this way you can specify list of files under root level field called | ||
`extraResources`. These files has configuration that Kubernetes understands, |
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.
s/has/have
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.
done
examples/extraResources/README.md
Outdated
Also the file paths under `extraResources` should be relative to the kedge file | ||
in which this config is specified. | ||
|
||
This does not change anything with respect to deploying application. |
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.
s/application/applications
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.
done
badd405
to
0b97b3f
Compare
@containscafeine changed all of it! |
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 looks good to me.
But let's wait for @containscafeine approval before merge
if err != nil { | ||
return nil, errors.Wrap(err, "failed to create Kubernetes objects") | ||
return nil, extraResources, errors.Wrap(err, "failed to create Kubernetes objects") |
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.
umm, any reason we are returning return nil, extraResources, "error"
and not return nil, nil, "error")
here and everywhere else?
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.
done
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.
- Also, this fails in case of passing directory to
-f-
.
Running kedge generate -f examples/extraResources/
it returns unable to transform data: No runtime objects created, possibly because not enough input data was passed
with a non zero exit code.
If a file has been mentioned in the extraResources
field, we need to not pass it further in the code.
- Passing absolute paths fail, which should not be the case.
Putting this in the file -
extraResources:
- /tmp/cronjob.yaml
and running $ kedge generate -f examples/extraResources/app.yaml
, I get file reading failed: open /home/concaf/kedge/src/github.com/kedgeproject/kedge/examples/extraResources/tmp/cronjob.yaml: no such file or directory
filepath.IsAbs
should be able to help us with that - https://golang.org/pkg/path/filepath/#IsAbs
fwiw, I did similar stuff in OpenCompose in this part - https://github.com/containscafeine/opencompose/blob/95d568b90965ae952d08593ea16702477d914dc5/pkg/encoding/v1/encoding.go#L604-L627 |
This fails if kedge files are in the same directory with Kubernetes resources. They both are YAML files. Kubernetes files should be placed in a different directory than Kedge files.
now I'm not sure if ignoring files form |
@kadel agreed, but this is a corner case, no? How about we add a check which makes sure that if the file passed in |
I'm not sure if ignoring files form extraResources is going to be possible, as you have to parse the file first to get extraResources array. And to parse it you have to know if its Kedge file or not ;-) |
Problem is that also what error you throw. As its not possible to know if meant to be Kubernetes file or invalid Kedge file |
Ahh my bad, yeah I meant that we will support only relative paths, because absolute paths make the config tied to a machine, which is not the case, so not allowing also makes sense. |
@surajssd disagree, it has to be left to the user. It's the convention used everywhere. e.g. any linux command, Dockerfile, Docker Compose files, Kubernetes volume mount paths, etc, etc. |
0b97b3f
to
64a5fae
Compare
@containscafeine updated the comment and code! |
@kadel maybe for this PR we can ignore the issue with Kubernetes files in the same directory, but I think it's worth adding an edge case check here some time later. We can track this as a bug in a separate issue, wdyt? |
64a5fae
to
6a9cd13
Compare
@containscafeine added can you check if it works for you |
With this root level field called `extraResources`, which is a list of file names of Kubernetes artifacts that can be fed to Kubernetes directly without kedge having to do any processing. Anything that is not supported in kedge can be provided using this field. Following is the example snippet of the app file that is using `extraResources` field to deploy a `secret.yaml` and a `cron-job.yaml` with the rest of kedge file. Here `secret.yaml` & `cron-jobs.yaml` reside in the same directory. e.g. ``` ... extraResources: - secret.yaml - cron-jobs.yaml ```
6a9cd13
to
f4053c4
Compare
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.
great work, @surajssd 🎉
With this root level field called
extraResources
, which is a listof file names of Kubernetes artifacts that can be fed to Kubernetes
directly without kedge having to do any processing.
Anything that is not supported in kedge can be provided using this
field. Following is the example snippet of the app file that is
using
extraResources
field to deploy asecret.yaml
and acron-job.yaml
with the rest of kedge file. Heresecret.yaml
&cron-jobs.yaml
reside in the same directory.e.g.
Fixes #157