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

Env var sources / downward API #6739

Merged
merged 1 commit into from
Apr 27, 2015
Merged

Conversation

pmorie
Copy link
Member

@pmorie pmorie commented Apr 12, 2015

As discussed in #6000 and #2316, relevant also to #386.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@pmorie
Copy link
Member Author

pmorie commented Apr 12, 2015

@bgrant0607 @smarterclayton @erictune @thockin @derekwaynecarr @mfojtik PTAL.

Preliminary WIP for comment. I don't think there's any controversy about the concepts here, based on the last community hangout. Looking for feedback on the factorings.

switch {
case envVar.ObjectInfo != nil:
objInfo := envVar.ObjectInfo
internalFieldPath, _, err := api.Scheme.ConvertFieldLabel(objInfo.APIVersion, "Pod", objInfo.FieldPath, "")
Copy link
Contributor

Choose a reason for hiding this comment

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

add the TODO: use Kind from ObjectInfo so it doesn't confuse people looking at this.

@pmorie
Copy link
Member Author

pmorie commented Apr 13, 2015

Taking this a little further today in terms of factoring within the kubelet. If anyone would like info added to the skeletal API, speak out.

I'll making the versioned API changes once people have a chance to chime in here.

@pmorie
Copy link
Member Author

pmorie commented Apr 13, 2015

@sdminonne fyi

@sdminonne
Copy link
Contributor

@pmorie thanks

@derekwaynecarr
Copy link
Member

@pmorie - my first impression is that I am good with this approach. my initial reaction was unsure if i liked the metadata.* syntax, but I have no other good alternative in mind so that lgtm.

@ironcladlou
Copy link
Contributor

Is there any reason to place security restrictions on the host source? Is it okay that any user can access host information via this mechanism? Right now it's limited to hostname, but I assume the set of fields will increase over time.

@@ -164,6 +164,20 @@ func TestEncode_Ptr(t *testing.T) {
Spec: api.PodSpec{
RestartPolicy: api.RestartPolicyAlways,
DNSPolicy: api.DNSClusterFirst,
Containers: []api.Container{
Copy link
Member Author

Choose a reason for hiding this comment

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

Debugging cruft; will remove

@pmorie
Copy link
Member Author

pmorie commented Apr 14, 2015

@bgrant0607 This is shaping up; what supplemental stuff does it need to go in with? I can think of:

  1. Pass through the examples to see where the downward API can be used instead
  2. Docs
  3. E2E test

@smarterclayton @thockin @derekwaynecarr any opinions on the above?

@@ -509,6 +509,33 @@ type EnvVar struct {
Name string `json:"name" description:"name of the environment variable; must be a C_IDENTIFIER"`
// Optional: defaults to "".
Value string `json:"value,omitempty" description:"value of the environment variable; defaults to empty string"`
// Optional: specify a source for the value of the EnvVar.
*EnvVarSource `json:"source,omitempty" description:"source for the environment variable's value; cannot be used if value is set"`
Copy link
Member

Choose a reason for hiding this comment

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

A pointer to an embedded struct is confusing. It needs to not be embedded, which would make sense because the json isn't embedded.

Copy link
Member

Choose a reason for hiding this comment

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

Re. the description: We can't tell whether value is "set", only whether it is empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

@bgrant0607 Are you suggesting instead:

// EnvVar represents an environment variable present in a Container.
type EnvVar struct {
    // Required: This must be a C_IDENTIFIER.
    Name string `json:"name" description:"name of the environment variable; must be a C_IDENTIFIER"`
    // Optional: defaults to "".
    Value string `json:"value,omitempty" description:"value of the environment variable; defaults to empty string"`
    // Optional; ObjectInfo represents a downward API request for a field of the object.
    //
    // Valid fields of this reference are:
    //
    // 1. APIVersion
    // 2. FieldPath
    //
    // No other fields may be specified.
    //
    // Currently ObjectInfo may be used to address the Name and Namespace
    // only.
    ObjectInfo *ObjectReference `json:"objectInfo,omitempty" description:"describes a field of the pod to use the value of; only APIVersion and FieldPath are accepted fields"`
    // Optional; HostInfo represents a downward API request for information about
    // the host.
    HostInfo *HostInfoSource `json:"hostInfo,omitempty" description:"describes information about the host to use"`
}

Copy link
Member Author

Choose a reason for hiding this comment

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

@bgrant0607 @smarterclayton I would be okay with having ObjectInfo become a field of EnvVar -- it would simplify the API greatly.

Copy link
Member

Choose a reason for hiding this comment

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

If we think there may be multiple sources in the future, then I prefer the extra level of nesting. I was objecting to the specific combination of a pointer to an anonymous Go struct. Name the field Source.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with that.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we should call it fieldValue, though, rather than objectInfo, to strengthen the association with value.

Copy link
Member

Choose a reason for hiding this comment

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

What do we want the JSON to look like?

{ 
    "name": "myvar",
    "source": { "objectInfo": { "fieldPath": ".metadata.name" } }
}

or

{ 
    "name": "myvar",
    "objectInfo": { "fieldPath": ".metadata.name" }
}

or

{ 
    "name": "myvar",
    "value": { "objectInfo": {"fieldPath": ".metadata.name" }}
}

If I parse this correctly it's #2 that we are getting, yes?

Copy link
Member

Choose a reason for hiding this comment

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

What about calling the sources something like "FromPod" or "ValueFromPod" ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@thockin Either of those names is more descriptive -- unless we feel like we want open-ended info about objects, which I don't think we do.

@pmorie
Copy link
Member Author

pmorie commented Apr 16, 2015

Gonna go with this factoring in my next pass unless someone speaks soon:

// EnvVar represents an environment variable present in a Container.
type EnvVar struct {
    // Required: This must be a C_IDENTIFIER.
    Name string `json:"name" description:"name of the environment variable; must be a C_IDENTIFIER"`
    // Optional: defaults to "".
    Value string `json:"value,omitempty" description:"value of the environment variable; defaults to empty string"`
    // Optional; ObjectInfo represents a downward API request for a field of the object.
    //
    // Valid fields of this reference are:
    //
    // 1. APIVersion
    // 2. FieldPath
    //
    // No other fields may be specified.
    //
    // Currently ObjectInfo may be used to address the Name and Namespace
    // only.
    ObjectInfo *ObjectReference `json:"objectInfo,omitempty" description:"describes a field of the pod to use the value of; only APIVersion and FieldPath are accepted fields"`
}

Scratching HostInfo, we can add it back in later if there's a need.

// 1. APIVersion
// 2. FieldPath
//
// No other fields may be specified.
Copy link
Member

Choose a reason for hiding this comment

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

This feels like an abuse of an existing type. Why not just define your own type?

@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

@bgrant0607 All comments should be fixed now

@smarterclayton
Copy link
Contributor

So now that this awesome feature is almost done... how do I choose my own names for environment variables for services?

@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

@smarterclayton We can implement a new env var source for that info

@smarterclayton
Copy link
Contributor

Is it a different source? Seems like it's the spec.portalIP and spec.port[0] field of a service with a given name and namespace.

@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

@smarterclayton

with a given name and namespace.

Wouldn't it just be the name, since we don't support cross-ns services?

@smarterclayton
Copy link
Contributor

It could be eventually. But yes, for now, just name.

----- Original Message -----

@smarterclayton

with a given name and namespace.

Wouldn't it just be the name, since we don't support cross-ns services?


Reply to this email directly or view it on GitHub:
#6739 (comment)

@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

@smarterclayton That sounds to me like:

type EnvVarSource struct {
  FieldPath        *ObjectFieldSelector
  ServiceFieldPath *NamedObjectFieldSelector
}

type NamedObjectFieldSelector {
    ObjectFieldSelector

    Name string
}

@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

Kicked shippable

@smarterclayton
Copy link
Contributor

And then we say... why do we have ServiceFieldPath and FieldPath together?

----- Original Message -----

@smarterclayton That sounds to me like:

type EnvVarSource struct {
  FieldPath        *ObjectFieldSelector
  ServiceFieldPath *NamedObjectFieldSelector
}

type NamedObjectFieldSelector {
  ObjectFieldSelector

  Name string
}

Reply to this email directly or view it on GitHub:
#6739 (comment)

@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

@smarterclayton this would definitely lurch us in the direction of ObjectReference

@smarterclayton
Copy link
Contributor

Yes. I'm not proposing any changes for this pull (since the types are the same) but I realized we got really focused on pod name/namespace. The follow-on will need to deal with the implications.

----- Original Message -----

@smarterclayton this would definitely lurch us in the direction of
ObjectReference


Reply to this email directly or view it on GitHub:
#6739 (comment)

@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

@smarterclayton Agree, I will make a new issue for service downward API

@thockin
Copy link
Member

thockin commented Apr 27, 2015

Services wanders into a whole different discussion - the pre-declaring
service-deps topic. I don't yet have an opinion as to whether we should
have an env var source way to do this, but I do think it is more
complicated that you have listed here.

Service have multiple ports - do I have to call out each one I want? How
do I express named ports, rather than indexed? etc.

On Mon, Apr 27, 2015 at 9:20 AM, Paul Morie notifications@github.com
wrote:

@smarterclayton https://github.com/smarterclayton Agree, I will make a
new issue for service downward API


Reply to this email directly or view it on GitHub
#6739 (comment)
.

@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

@thockin I am looking at the downward API for service envs as orthogonal to pre-declaring service dependencies. I think dependencies will take pre-start hooks and should be separate in the API from how the vars are constructed.

@smarterclayton
Copy link
Contributor

Exactly. But exposing services via this mechanism is strictly better in my opinion than making up a bunch of env vars (making up one env var I can get behind, just not 100 different variants).

----- Original Message -----

Services wanders into a whole different discussion - the pre-declaring
service-deps topic. I don't yet have an opinion as to whether we should
have an env var source way to do this, but I do think it is more
complicated that you have listed here.

Service have multiple ports - do I have to call out each one I want? How
do I express named ports, rather than indexed? etc.

On Mon, Apr 27, 2015 at 9:20 AM, Paul Morie notifications@github.com
wrote:

@smarterclayton https://github.com/smarterclayton Agree, I will make a
new issue for service downward API


Reply to this email directly or view it on GitHub
#6739 (comment)
.


Reply to this email directly or view it on GitHub:
#6739 (comment)

@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

Ugh. Rebasing

@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

Rebased

@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

Local e2e run looks good.

@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

@bgrant0607 Does this need anything else?

@@ -166,6 +166,11 @@ func init() {
obj.ExternalID = obj.ID
}
},
func(obj *ObjectFieldSelector) {
Copy link
Member

Choose a reason for hiding this comment

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

Did you confirm that this isn't called when the pointer is nil?

@bgrant0607
Copy link
Member

The ObjectFieldSelector field descriptions didn't get changed as I asked, but my review latency is very high right now, so I'm not going to block on that.

LGTM.

bgrant0607 added a commit that referenced this pull request Apr 27, 2015
Env var sources / downward API
@bgrant0607 bgrant0607 merged commit 2648ae8 into kubernetes:master Apr 27, 2015
@pmorie
Copy link
Member Author

pmorie commented Apr 27, 2015

@bgrant0607 Dang, I thought I had absolutely everything. I will fix them in a follow-up.

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.

9 participants