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

User can specify the namespace in yaml for knative-serving #2708

Merged
merged 9 commits into from
Jan 18, 2019

Conversation

zxDiscovery
Copy link

Fixes #2703

Proposed Changes

User can set knative-serving deployment namespace in yaml file. The default namespace for knative-serving is also knative-serving

Release Note

NONE

@knative-prow-robot knative-prow-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 13, 2018
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@zxDiscovery: 0 warnings.

In response to this:

Fixes #2703

Proposed Changes

User can set knative-serving deployment namespace in yaml file. The default namespace for knative-serving is also knative-serving

Release Note

NONE

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Dec 13, 2018
@markusthoemmes
Copy link
Contributor

@zxDiscovery Thanks for your PR. Is this work in progress? As it stands, how'd we actually configure the namespace when deploying Knative?

@zxDiscovery
Copy link
Author

@markusthoemmes I tested it based on the code of v0.2.2 and it works.
For example. If user want to specify the namespace knative-system for deployment autoscaler, it can set in the deployment yaml file as follows:

kind: Deployment
metadata:
  name: autoscaler
  namespace: knative-system
spec:
  template:
    spec:
      containers:
        env:
        - name: SYSTEM_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace

@markusthoemmes
Copy link
Contributor

Right, is this how we actually want to ship this? Is there a way to globally set this value in a config-map or something like that?

@zxDiscovery
Copy link
Author

This method was copied from knative-build. If this method is not well, I will find anther better solution.

@zxDiscovery
Copy link
Author

@markusthoemmes I think this method to set the namespace is simple. If we just use config-map to set the namespace, it may be more complicated for this.

@markusthoemmes
Copy link
Contributor

@zxDiscovery Yep, the knative-build commit makes sense to me. Should we add the same changes here (setting the Environment variable based on the namespace the YAML is applied to for each deployment)?

@zxDiscovery
Copy link
Author

@markusthoemmes The current knative serving, build and eventing are deployed in three namespaces. They are all belong to knative, and why we don't put them into the same namespaces so that the chart can management easily. I hear there is ongoing work to explore make this configurable(#2623). If we want to this configuration work, knative-serving need to be deployed in some other namespace. So I think we need add the same changes here.

@markusthoemmes
Copy link
Contributor

@zxDiscovery right. I'm referring to the changes that've been made when build introduced this mechanism. See this commit: knative/build@64938e4.

It also adds the SYSTEM_NAMESPACE environment variable to every deployment. Would it make sense to do the same here?

@zxDiscovery
Copy link
Author

@markusthoemmes Do you mean the environment variable SYSTEM_NAMESPACE is duplicate and may cause conflicts?

@markusthoemmes
Copy link
Contributor

No I'm speaking of the changes that PR in build made:

  1. It took the variable from the environment if it's there (same as you did here)
  2. It added
env:
  - name: SYSTEM_NAMESPACE
    valueFrom:
      fieldRef:
        fieldPath: metadata.namespace

To all deployments to actually set that value accordingly.

Shall we do the second step here as well?

@zxDiscovery
Copy link
Author

@markusthoemmes Oh I see. Yes, we need do this for the yaml file. I will update this.

@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 14, 2018
@markusthoemmes
Copy link
Contributor

/ok-to-test

To me, the approach seems fine as it's also already used over in build.

/assign @mattmoor

@knative-prow-robot knative-prow-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Dec 19, 2018
)

func init() {
Copy link
Contributor

@greghaynes greghaynes Dec 19, 2018

Choose a reason for hiding this comment

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

What do you think of making this just a getter method rather than having an init which fills in a global (and therefore needs care taken to ensure its called before referencing the global)? I.e.

const (
  NamespaceEnvKey = "SYSTEM_NAMESPACE"
)

func Namespace() string {
  return os.Getenv(NamespaceEnvKey)
}

Copy link
Author

Choose a reason for hiding this comment

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

But if use this method, the default namespace knative-serving can't be set. We need the default namespace knative-serving in current version.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think @greghaynes was referring to actually adding the defaulting logic into the getter, i.e.:

const (
  NamespaceEnvKey = "SYSTEM_NAMESPACE"
)

func Namespace() string {
  if ns := os.Getenv(NamespaceEnvKey); ns != "" {
    return ns
  }
  return "knative-serving"
}

I think init() is called automatically before running main though. Both approaches might be valid in this case, knative-build opted for the init function.

Copy link
Member

Choose a reason for hiding this comment

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

+1 on getter. Why do we need the default? Tests?

I'd like so see if we can create a shared library for this in knative/pkg to standardize this across Knative.

Copy link
Author

Choose a reason for hiding this comment

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

@mattmoor I also hope the knative-serving doesn't need the default namespace and user can free to specify the namespace. But the current knative can't put the serving, build and eventing into the same namespace. The current doc and test case are all specify the knative-serving in knative-serving namespace. And also knative-build specify in knative-build namespace. So I follow by the code of knative-build to change here.

Copy link
Member

Choose a reason for hiding this comment

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

I understand that we can't (yet) put things in the same namespace, but this is one of a number of changes to move in that direction.

I'd like to see us have a shared library for this in knative/pkg that folks can pull in to determine the system namespace, assuming it's configured as you have in the yamls.

I'm wondering when the defaulting here actually kicks in (tests?), so that we can take steps to address that.

Copy link
Author

Choose a reason for hiding this comment

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

After I check the commit history, the namespace is hardcode(#1101) in pkg/names.go from the beginning. I think this is not only for testing, but also for deployment.

// GetServingSystemNamespace returns the namespace where
// serving controllers are deployed to.
func GetServingSystemNamespace() string {
	return "knative-serving-system"
}

After #1549, pkg/names.go move to pkg/system/names.go, the code has changed as follows:

package system

const (
	// Namespace holds the K8s namespace where our serving system
	// components run.
	Namespace = "knative-serving"
)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think @mattmoor's question was:

Once you apply your change of reading the namespace from environment (including the YAML changes), is there a place where the default is actually used (hence: do we even need it?).

Your changes make sure that all of our components are properly configured so either there is a place somewhere that isn't configured (and might need to be?) or we don't need the default at all.

Copy link
Author

Choose a reason for hiding this comment

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

The default namespaces is unnecessary. The getter method is better than current. But there will be more code changes. I have updated the code.

@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 7, 2019
@zxDiscovery zxDiscovery force-pushed the serving-namespace branch 2 times, most recently from 2d47ccd to 18f067f Compare January 8, 2019 06:05
@zxDiscovery
Copy link
Author

/retest

2 similar comments
@zxDiscovery
Copy link
Author

/retest

@zxDiscovery
Copy link
Author

/retest

@zxDiscovery zxDiscovery force-pushed the serving-namespace branch 2 times, most recently from 50e45de to 83e6150 Compare January 17, 2019 09:00
@@ -303,7 +302,7 @@ func main() {
}()

// Open a websocket connection to the autoscaler
autoscalerEndpoint := fmt.Sprintf("ws://%s.%s.svc.%s:%d", servingAutoscaler, system.Namespace, utils.GetClusterDomainName(), servingAutoscalerPort)
autoscalerEndpoint := fmt.Sprintf("ws://%s.%s.svc.%s:%d", servingAutoscaler, "knative-serving", utils.GetClusterDomainName(), servingAutoscalerPort)
Copy link
Author

Choose a reason for hiding this comment

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

Here, we must get the namespace knative-serving which deploy the service autoscaler. If we use system.Namespace() only can get default namespaces knative-testing if we set the default value in test lib. Do you have some better method to get the namespaces which autoscaler deployed. @mattmoor

Copy link
Member

Choose a reason for hiding this comment

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

This means that we're somehow getting the test library linked into one of our application binaries, which is troubling.

@@ -93,6 +93,7 @@ func initEnv() {
servingNamespace = util.GetRequiredEnvOrFatal("SERVING_NAMESPACE", logger)
servingRevision = util.GetRequiredEnvOrFatal("SERVING_REVISION", logger)
servingAutoscaler = util.GetRequiredEnvOrFatal("SERVING_AUTOSCALER", logger)
autoscalerNamespace = util.GetRequiredEnvOrFatal("AUTOSCALER_NAMESPACE", logger)
Copy link
Author

Choose a reason for hiding this comment

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

Can we use the environment value to transmit the autoscaler namespace?@mattmoor

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why this is different from system.Namespace(), I'd rather chase the root cause than work around it like this.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I understand (sorry it took so long).

I would change this to system.Namespace(), and... (see next comment)

@@ -131,6 +131,9 @@ func makeQueueContainer(rev *v1alpha1.Revision, loggingConfig *logging.Config, a
}, {
Name: "USER_PORT",
Value: strconv.Itoa(int(userPort)),
}, {
Name: "AUTOSCALER_NAMESPACE",
Value: "knative-serving",
Copy link
Author

Choose a reason for hiding this comment

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

The queue sidecar's container spec created by the function makeQueueContainer. I can add an environment value to transmit the knative-serving. But the namespace at here is also hardcode. I don't know is this right? @mattmoor

Copy link
Member

Choose a reason for hiding this comment

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

I would change this to:

			Name:  system.NamespaceEnvKey,
			Value: system.Namespace(),

@@ -135,6 +136,9 @@ func makeQueueContainer(rev *v1alpha1.Revision, loggingConfig *logging.Config, a
}, {
Name: "USER_PORT",
Value: strconv.Itoa(int(userPort)),
}, {
Name: system.NamespaceEnvKey,
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 this requires an update to queue_test.go, which will need to link our new library.

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/autoscaling/kpa/kpa.go 87.5% 84.1% -3.4

@@ -381,6 +393,9 @@ func TestMakeQueueContainer(t *testing.T) {
}, {
Name: "USER_PORT",
Value: strconv.Itoa(v1alpha1.DefaultUserPort),
}, {
Name: "SYSTEM_NAMESPACE",
Value: "knative-testing",
Copy link
Member

Choose a reason for hiding this comment

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

we generally use system.Namespace() to avoid hard-coding the string.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/autoscaling/kpa/kpa.go 84.1% 87.5% 3.4

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 18, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mattmoor, zxDiscovery

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:

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 18, 2019
@knative-prow-robot knative-prow-robot merged commit 3d137ac into knative:master Jan 18, 2019
@zxDiscovery zxDiscovery deleted the serving-namespace branch January 23, 2019 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants