-
Notifications
You must be signed in to change notification settings - Fork 64
feat : Add support to add Service annotations from DevWorkspaceRouting configuration (#1293) #1439
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
base: main
Are you sure you want to change the base?
Conversation
Skipping CI for Draft Pull Request. |
abfb699
to
708d590
Compare
/ok-to-test |
2c63671
to
96c6a02
Compare
/ok-to-test |
96c6a02
to
da6f7fd
Compare
da6f7fd
to
34576bb
Compare
@@ -36,9 +36,10 @@ type DevWorkspaceMetadata struct { | |||
|
|||
// GetDiscoverableServicesForEndpoints converts the endpoint list into a set of services, each corresponding to a single discoverable | |||
// endpoint from the list. Endpoints with the NoneEndpointExposure are ignored. | |||
func GetDiscoverableServicesForEndpoints(endpoints map[string]controllerv1alpha1.EndpointList, meta DevWorkspaceMetadata) []corev1.Service { | |||
func GetDiscoverableServicesForEndpoints(routingSpec controllerv1alpha1.DevWorkspaceRoutingSpec, meta DevWorkspaceMetadata) []corev1.Service { |
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.
If possible, it would be best if this function signature (and also GetServiceForEndpoints
) are not changed so that function consumers are not affected. For example for che-operator, we use solver.GetServiceForEndpoints
in che_routing.go
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.
Or, if we want to change the function signature, maybe we can refactor it to use "Functional Options Pattern" so that new fields can be easily added without breaking consumer code: https://golang.cafe/blog/golang-functional-options-pattern.html ?
For example something similar to:
solver.GetDiscoverableServicesForEndpoints(
solver.WithEndpoints(endpoints),
solver.WithMetadata(metadata),
solver.WithAnnotations(annotations),
)
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.
hmm, good point. I wasn't aware about this. Let me think if it's possible to do it without changing method signature.
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.
Looking closely at the changes, Currently Service generation is closely tied to Endpoints, We're going over component to endpoint map and creating Service accordingly. At this point we know for which component we're creating Service, so we can add appropriate annotations for appropriate component.
However, if we want to move this logic outside and set annotations after creating the Service; it would be uncertain which Service belongs to which component. If we decide to mutate Service with a marker label containing component, it should become possible:
I mean replacing this
devworkspace-operator/controllers/controller/devworkspacerouting/solvers/common.go
Lines 60 to 63 in 492c050
Namespace: meta.Namespace, | |
Labels: map[string]string{ | |
constants.DevWorkspaceIDLabel: meta.DevWorkspaceId, | |
}, |
Labels: map[string]string{
constants.DevWorkspaceIDLabel: meta.DevWorkspaceId,
+ "workspace.dev/component": componentName,
},
We can then iterate over generated Services and apply annotations by reading component label (that can be deleted after processing). If you think this approach is okay then I can make changes to keep original method signature.
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.
IMHO it should be the DWO that provides the API that conforms with the Devfile spec, therefore, it makes more sense to apply annotations within the functions provided by DWO
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.
Umm, Not 100% sure I understand but do you mean it's okay to keep these changes?
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dkwon17, rohanKanojia 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 |
} | ||
|
||
var isOpenShift = func() bool { | ||
return infrastructure.IsOpenShift() |
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.
Since infrastructure.IsOpenShift()
is commonly used in the codebase, I don't think this fcuntion is necessary
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.
Actually, I had exposed this for testing. I wanted to mock the behavior of infrastructure.IsOpenShift()
method.
Let me think on how I can do it without adding this 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.
Thanks, I see there is already a method created for mocking behavior of this method for tests
devworkspace-operator/pkg/infrastructure/cluster.go
Lines 57 to 60 in cf4c38d
// InitializeForTesting is used to mock running on a specific type of cluster (Kubernetes, OpenShift) in testing code. | |
func InitializeForTesting(currentInfrastructure Type) { | |
current = currentInfrastructure | |
initialized = true |
I'll use already provided method instead of what I added.
@@ -43,12 +43,38 @@ var nginxIngressAnnotations = func(endpointName string, endpointAnnotations map[ | |||
return annotations | |||
} | |||
|
|||
func serviceAnnotations(sourceAnnotations map[string]string, isDiscoverable bool, serviceRoutingConfig controllerv1alpha1.Service) map[string]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.
func serviceAnnotations(sourceAnnotations map[string]string, isDiscoverable bool, serviceRoutingConfig controllerv1alpha1.Service) map[string]string { | |
func mergeServiceAnnotations(sourceAnnotations map[string]string, serviceRoutingConfig controllerv1alpha1.Service) map[string]string { |
I suggest "merge" for more clarity.
Also, for readability and simplicity I think it would be best to avoid boolean flags and instead call the function like:
serviceAnnotations := map[string]string{
constants.DevWorkspaceDiscoverableServiceAnnotation: "true",
}
mergeServiceAnnotations(serviceAnnotations, routingSpec.Service[componentName]),
WDYT?
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.
Okay, I'll update it as per your comments.
34576bb
to
836ed36
Compare
New changes are detected. LGTM label has been removed. |
Signed-off-by: Rohan Kumar <[email protected]>
Signed-off-by: Rohan Kumar <[email protected]>
Signed-off-by: Rohan Kumar <[email protected]>
836ed36
to
c2a3755
Compare
Signed-off-by: Rohan Kumar <[email protected]>
@rohanKanojia: The following test failed, say
Full PR test history. Your PR dashboard. 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-sigs/prow repository. I understand the commands that are listed here. |
What does this PR do?
Add support for adding Service annotations from DevWorkspace component configuration to actual Service created by DevWorkspace operator
service
that containsannotation
field for storing annotations in DevWorkspaceRouting CustomResourceDefinitionSigned-off-by: Rohan Kumar [email protected]
What issues does this PR fix or reference?
Fix #1293
Is it tested? How?
PR Checklist
/test v8-devworkspace-operator-e2e, v8-che-happy-path
to trigger)v8-devworkspace-operator-e2e
: DevWorkspace e2e testv8-che-happy-path
: Happy path for verification integration with Che