-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
User can specify the namespace in yaml for knative-serving #2708
Conversation
There was a problem hiding this 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.
@zxDiscovery Thanks for your PR. Is this work in progress? As it stands, how'd we actually configure the namespace when deploying Knative? |
@markusthoemmes I tested it based on the code of v0.2.2 and it works.
|
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? |
This method was copied from knative-build. If this method is not well, I will find anther better solution. |
@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. |
@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)? |
@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. |
@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 |
@markusthoemmes Do you mean the environment variable |
No I'm speaking of the changes that PR in build made:
To all deployments to actually set that value accordingly. Shall we do the second step here as well? |
@markusthoemmes Oh I see. Yes, we need do this for the yaml file. I will update this. |
decbc75
to
97fde11
Compare
/ok-to-test To me, the approach seems fine as it's also already used over in build. /assign @mattmoor |
pkg/system/names.go
Outdated
) | ||
|
||
func init() { |
There was a problem hiding this comment.
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)
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"
)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
2d47ccd
to
18f067f
Compare
/retest |
2 similar comments
/retest |
/retest |
50e45de
to
83e6150
Compare
cmd/queue/main.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
cmd/queue/main.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(),
cbb6729
to
c1327d7
Compare
@@ -135,6 +136,9 @@ func makeQueueContainer(rev *v1alpha1.Revision, loggingConfig *logging.Config, a | |||
}, { | |||
Name: "USER_PORT", | |||
Value: strconv.Itoa(int(userPort)), | |||
}, { | |||
Name: system.NamespaceEnvKey, |
There was a problem hiding this comment.
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.
c1327d7
to
9d46532
Compare
The following is the coverage report on pkg/.
|
@@ -381,6 +393,9 @@ func TestMakeQueueContainer(t *testing.T) { | |||
}, { | |||
Name: "USER_PORT", | |||
Value: strconv.Itoa(v1alpha1.DefaultUserPort), | |||
}, { | |||
Name: "SYSTEM_NAMESPACE", | |||
Value: "knative-testing", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
49941fd
to
7b7d4b5
Compare
This makes `pkg/system` panic if `SYSTEM_NAMESPACE` is not set. For tests, it exposes a simple library you can link to set this variable to a suitable namespace.
7b7d4b5
to
d59ab7f
Compare
The following is the coverage report on pkg/.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[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 |
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