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

906- variable substitution in kubernetes uri content #138

Merged
merged 6 commits into from
Aug 18, 2022

Conversation

yangcao77
Copy link
Collaborator

@yangcao77 yangcao77 commented Aug 11, 2022

What does this PR do?:

This PR converts kubernetest uri field to the inlined field with actual content in the devfileObj object in memory; so that the grobal variable defined can be substituted. An attribute api.devfile.io/kubeComponent-originalURI will be added to the kubernetes component as well.
The PR also modified writer to check for the specific attribute and restore the uri back before write to the devfile; so that we are not modifying user's devfile content.

Which issue(s) this PR fixes:

fixes devfile/api#906

PR acceptance criteria:

Testing and documentation do not need to be complete in order for this PR to be approved. We just need to ensure tracking issues are opened.

  • Open new test/doc issues under the devfile/api repo
  • Check each criteria if:
  • There is a separate tracking issue. Add the issue link under the criteria
    or
  • test/doc updates are made as part of this PR
  • If unchecked, explain why it's not needed

How to test changes / Special notes to the reviewer:

Signed-off-by: Stephanie <yangcao@redhat.com>
Signed-off-by: Stephanie <yangcao@redhat.com>
Signed-off-by: Stephanie <yangcao@redhat.com>
Signed-off-by: Stephanie <yangcao@redhat.com>
pkg/devfile/parser/parse.go Outdated Show resolved Hide resolved
pkg/devfile/parser/parse.go Outdated Show resolved Hide resolved
Signed-off-by: Stephanie <yangcao@redhat.com>
@@ -7,7 +7,8 @@ import (

// Default filenames for create devfile
const (
OutputDevfileYamlPath = "devfile.yaml"
OutputDevfileYamlPath = "devfile.yaml"
K8sLikeComponentOriginalURIKey = "devfile.io/k8sLikeComponent-originalURI"
Copy link
Member

Choose a reason for hiding this comment

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

wonder if we should keep it consistent like

// attribute key of the plugin overridden element resource information
	PluginOverrideAttribute = "api.devfile.io/plugin-override-from"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

return err
}
for _, kubeComp := range kubeComponents {
if kubeComp.Kubernetes.Uri != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if kubeComp.Kubernetes.Uri != "" {
if kubeComp.Kubernetes != nil && kubeComp.Kubernetes.Uri != "" {

tech not needed but i would still put it in place to avoid any panics if somehow GetComponents(getKubeCompOptions) fails

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

@@ -11,6 +14,11 @@ import (
// WriteYamlDevfile creates a devfile.yaml file
func (d *DevfileObj) WriteYamlDevfile() error {

// Check kubernetes components, and restore original uri content
err := restoreK8sCompURI(d)
Copy link
Member

Choose a reason for hiding this comment

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

just a thought:
this func would be checking for the attribute every time it is called to write devfile. I wonder if we should introduce some property in the object that we can use to keep track:


type DevfileObj struct {

	// Ctx has devfile context info
	Ctx devfileCtx.DevfileCtx

	// Data has the devfile data
	Data data.DevfileData

        // convert
        ConvertUriToInlined bool
}

Copy link
Collaborator Author

@yangcao77 yangcao77 Aug 17, 2022

Choose a reason for hiding this comment

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

I do not want the value to be direct accessible for all devobj consumers.. so added into DevfileObj.ctx.convertUriToInlined instead.

Copy link
Member

Choose a reason for hiding this comment

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

Thinking if we should really keep this context? Because context refers to a devfile context but otherwise its ok i guess

Comment on lines 64 to 66
if err != nil && err.Error() != keyNotFoundErr.Error() {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

you can also do it this way:

Suggested change
if err != nil && err.Error() != keyNotFoundErr.Error() {
return err
}
if err != nil {
if _, ok := err.(*attributes.KeyNotFoundError); !ok {
return err
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

Signed-off-by: Stephanie <yangcao@redhat.com>
@openshift-ci
Copy link

openshift-ci bot commented Aug 18, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: maysunfaisal, yangcao77

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:
  • OWNERS [maysunfaisal,yangcao77]

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

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