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

Make environment variable population more generic #125

Merged
merged 7 commits into from
Mar 26, 2021
Merged

Make environment variable population more generic #125

merged 7 commits into from
Mar 26, 2021

Conversation

viveklak
Copy link
Contributor

Fixes #122

Copy link
Contributor

@lukehoban lukehoban left a comment

Choose a reason for hiding this comment

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

Looks great. One question naming.

"aws:region": "us-east-2",
},
Stack: stackName,
ProjectRepo: "https://github.com/metral/test-s3-op-project", // TODO: relocate to some other repo
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a reminder - we should probably open an issue to track migrating these test cases to a Pulumi repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Cut #126 to track this.

@@ -57,6 +57,11 @@ spec:
items:
type: string
type: array
envSecretsFromPath:
Copy link
Contributor

Choose a reason for hiding this comment

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

These are strictly secrets, are they? In the sense that the other uses of these he word Secret here are about K8s Secret objects.

Are there other precedents for naming for things like this in other operators we could model after? Not sure if this pattern has common terminology associated with it?

Copy link
Contributor Author

@viveklak viveklak Mar 25, 2021

Choose a reason for hiding this comment

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

Fair point. I was positioning this as an alternative to envSecrets. It can just be called envFromPath instead.

I was also wondering if it makes sense to take a slightly different tack on this by modeling things as a reference instead. For instance for #97 I can foresee us wanting to support literal, secret reference, environment variable or a file as well and could reuse the same model. As a result I am proposing adding a ResourceRef type. Other operators seem to take a similar approach.

Update - I have switched to this model so the result is a bit more generic and reusable.

type: string
required:
- name
- namespace
Copy link
Member

Choose a reason for hiding this comment

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

Seems like namespace could be optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


// ResourceRef identifies a resource from which information can be loaded.
type ResourceRef struct {
// SelectorType is required and signifies the type of selector. Should be one of:
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
// SelectorType is required and signifies the type of selector. Should be one of:
// SelectorType is required and signifies the type of selector. Must be one of:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@viveklak viveklak changed the title Add support for filesystem based secrets Make environment variable population more generic Mar 25, 2021
@viveklak
Copy link
Contributor Author

@lukehoban @lblackstone sorry for the noise. Could you take another look? I went ahead with the approach I proposed in #125 (comment)

} else {
return errors.Errorf("Mising secret reference in ResourceRef for '%s'", envVar)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Should add a default case that returns error just to be safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, updated.

envVarVal := os.Getenv(ref.Env.Name)
w.SetEnvVar(envVar, envVarVal)
} else {
return errors.Errorf("Missing env reference in ResourceRef for '%s'", envVar)
Copy link
Member

Choose a reason for hiding this comment

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

nit: This syntax is slightly cleaner

Suggested change
return errors.Errorf("Missing env reference in ResourceRef for '%s'", envVar)
return errors.Errorf("Missing env reference in ResourceRef for %q", envVar)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines 389 to 391
return fetched.Status.LastUpdate.LastSuccessfulCommit == stack.Spec.Commit &&
fetched.Status.LastUpdate.LastAttemptedCommit == stack.Spec.Commit &&
fetched.Status.LastUpdate.State == pulumiv1alpha1.SucceededStackStateMessage
Copy link
Member

Choose a reason for hiding this comment

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

If this is done commonly, it would be good to expose as a function. Fine for this test, if not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

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

Successfully merging this pull request may close these issues.

Decouple API token and cloud provider token from secrets
3 participants