Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

feat(spec): add support for extraResources #173

Merged
merged 1 commit into from
Aug 1, 2017

Conversation

surajssd
Copy link
Member

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

Fixes #157

@kedge-bot
Copy link
Collaborator

@surajssd, thank you for the pull request! We'll ping some people to review your PR. @containscafeine, please review this.

@kedge-bot kedge-bot requested a review from concaf July 24, 2017 07:30
@surajssd
Copy link
Member Author

surajssd commented Jul 24, 2017

TODO:

  • Add README to the example directory
  • Add to the file refernce doc about this

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"
Copy link
Member Author

@surajssd surajssd Jul 24, 2017

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)

@surajssd
Copy link
Member Author

blocked on #172

@surajssd surajssd force-pushed the k8s-artifacts-passing branch 2 times, most recently from e1e9dc0 to b0006fe Compare July 24, 2017 11:55
@surajssd surajssd requested a review from kadel July 24, 2017 11:56
@surajssd
Copy link
Member Author

since #172 is merged this is not blocked anymore and open to review

@surajssd
Copy link
Member Author

ping: @containscafeine @kadel

@surajssd
Copy link
Member Author

@containscafeine rebased!

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
Copy link
Member

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

Copy link
Member Author

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) {
Copy link
Member

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)

Copy link
Member Author

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) {
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@kadel
Copy link
Member

kadel commented Jul 28, 2017

Just a few missing comments and doc fix, otherwise it looks good to me 👍

@surajssd surajssd force-pushed the k8s-artifacts-passing branch 2 times, most recently from 3f76f88 to 3c8b711 Compare July 31, 2017 04:16
@surajssd
Copy link
Member Author

ping @containscafeine

Copy link
Collaborator

@concaf concaf left a 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


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
Copy link
Collaborator

Choose a reason for hiding this comment

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

one of the mechanisms

Copy link
Collaborator

Choose a reason for hiding this comment

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

s/it's/its

Copy link
Member Author

Choose a reason for hiding this comment

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

done

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
Copy link
Collaborator

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

Copy link
Member Author

Choose a reason for hiding this comment

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

done

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`.
Copy link
Collaborator

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

Copy link
Member Author

Choose a reason for hiding this comment

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

done

```

So in this way you can specify list of files under root level field called
`extraResources`. These files has configuration that Kubernetes understands,
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/has/have

Copy link
Member Author

Choose a reason for hiding this comment

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

done

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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/application/applications

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@surajssd surajssd force-pushed the k8s-artifacts-passing branch 2 times, most recently from badd405 to 0b97b3f Compare July 31, 2017 11:50
@surajssd
Copy link
Member Author

@containscafeine changed all of it!

Copy link
Member

@kadel kadel left a 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")
Copy link
Collaborator

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@concaf concaf left a comment

Choose a reason for hiding this comment

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

  1. 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.

  1. 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

@concaf
Copy link
Collaborator

concaf commented Jul 31, 2017

@kadel
Copy link
Member

kadel commented Jul 31, 2017

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.

This fails if kedge files are in the same directory with Kubernetes resources. They both are YAML files. -f reads all *.yml and *.yaml files from the directory. It doesn't know what is Kubernetes file and what is Kedge files, so all the files are treated as Kedge files.

Kubernetes files should be placed in a different directory than Kedge files.
This is something that we already discussed somewhere.

examples/extraResources
├── app.yaml
├── kubernetes
│   └── cronjob.yaml
└── README.md
extraResources:
- kubernetes/cronjob.yaml

now kedge apply -f examples/extraResources is going to work.

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 ;-)

@concaf
Copy link
Collaborator

concaf commented Jul 31, 2017

@kadel agreed, but this is a corner case, no? How about we add a check which makes sure that if the file passed in extraResources is placed in the same directory, then we don't parse it?
We won't check if the file is valid Kubernetes or not, just that if it's present in the current directory, it's ignored.

@kadel
Copy link
Member

kadel commented Jul 31, 2017

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 ;-)

@kadel
Copy link
Member

kadel commented Jul 31, 2017

Problem is that also what error you throw. As its not possible to know if meant to be Kubernetes file or invalid Kedge file

@surajssd
Copy link
Member Author

surajssd commented Jul 31, 2017

Passing absolute paths fail, which should not be the case.

@containscafeine we will support only absolute paths

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.

@concaf
Copy link
Collaborator

concaf commented Jul 31, 2017

@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.
Also, it's very confusing since the user tends to pass both relative and absolute paths in any path field.

@surajssd
Copy link
Member Author

@containscafeine updated the comment and code!

@concaf
Copy link
Collaborator

concaf commented Jul 31, 2017

@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?

@surajssd
Copy link
Member Author

surajssd commented Aug 1, 2017

Passing absolute paths fail, which should not be the case.

@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
```
Copy link
Collaborator

@concaf concaf left a comment

Choose a reason for hiding this comment

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

great work, @surajssd 🎉

@concaf concaf merged commit 6cb69fe into kedgeproject:master Aug 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants