You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "wmedvede (via GitHub)" <gi...@apache.org> on 2023/11/22 14:34:59 UTC

[PR] kie-issues-308: Operator driven service discovery API Phase2 [incubator-kie-kogito-serverless-operator]

wmedvede opened a new pull request, #309:
URL: https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/309

       - Add the discovery of kubernetes Deployment, StatefulSet, and Ingress objects to the service discovery API.
   
   <!--
   
   Welcome to the SonataFlow Operator! Before contributing, make sure to:
   
   - Rebase your branch on the latest upstream main
   - Link any relevant issues, PR's, or documentation
   - Check that the commit message is concise and helpful:
       - When fixing an issue, add "Closes #<ISSUE_NUMBER>"
   - Follow the below checklist 
   
   -->
   
   **Description of the change:**
   
   
   **Motivation for the change:**
   
   
   **Checklist**
   
   - [ ] Add or Modify a unit test for your change
   - [ ] Have you verified that tall the tests are passing?
   
   <details>
   <summary>
   How to backport a pull request to a different branch?
   </summary>
   
   In order to automatically create a **backporting pull request** please add one or more labels having the following format `backport-<branch-name>`, where `<branch-name>` is the name of the branch where the pull request must be backported to (e.g., `backport-7.67.x` to backport the original PR to the `7.67.x` branch).
   
   > **NOTE**: **backporting** is an action aiming to move a change (usually a commit) from a branch (usually the main one) to another one, which is generally referring to a still maintained release branch. Keeping it simple: it is about to move a specific change or a set of them from one branch to another.
   
   Once the original pull request is successfully merged, the automated action will create one backporting pull request per each label (with the previous format) that has been added.
   
   If something goes wrong, the author will be notified and at this point a manual backporting is needed.
   
   > **NOTE**: this automated backporting is triggered whenever a pull request on `main` branch is labeled or closed, but both conditions must be satisfied to get the new PR created.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] kie-issues-308: Operator driven service discovery API Phase2 [incubator-kie-kogito-serverless-operator]

Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini merged PR #309:
URL: https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/309


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] kie-issues-308: Operator driven service discovery API Phase2 [incubator-kie-kogito-serverless-operator]

Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on code in PR #309:
URL: https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/309#discussion_r1402690789


##########
controllers/discovery/discovery.go:
##########
@@ -57,6 +59,7 @@ type ResourceUri struct {
 	GVK          v1.GroupVersionKind
 	Namespace    string
 	Name         string
+	Port         string

Review Comment:
   +1, I will go back to the custom query attribute, which I had in the previous PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] kie-issues-308: Operator driven service discovery API Phase2 [incubator-kie-kogito-serverless-operator]

Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on PR #309:
URL: https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/309#issuecomment-1824702588

    @ricardozanini suggestions were added.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] kie-issues-308: Operator driven service discovery API Phase2 [incubator-kie-kogito-serverless-operator]

Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on code in PR #309:
URL: https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/309#discussion_r1402234188


##########
controllers/discovery/kubernetes_catalog.go:
##########
@@ -58,21 +72,97 @@ func (c k8sServiceCatalog) resolveServiceQuery(ctx context.Context, uri Resource
 }
 
 func (c k8sServiceCatalog) resolvePodQuery(ctx context.Context, uri ResourceUri, outputFormat string) (string, error) {
-	if pod, service, err := findPodAndReferenceServiceByPodLabels(ctx, c.Client, uri.Namespace, uri.Name); err != nil {
+	if pod, serviceList, err := findPodAndReferenceServices(ctx, c.Client, uri.Namespace, uri.Name); err != nil {
 		return "", err
 	} else {
-		if service != nil {
-			if serviceUri, err := resolveServiceUri(service, uri.GetPort(), outputFormat); err != nil {
+		if serviceList != nil && len(serviceList.Items) > 0 {
+			referenceService := selectBestSuitedServiceByCustomLabels(serviceList, uri.CustomLabels)
+			return resolveServiceUri(referenceService, uri.GetPort(), outputFormat)
+		} else {
+			return resolvePodUri(pod, "", uri.GetPort(), outputFormat)
+		}
+	}
+}
+
+func (c k8sServiceCatalog) resolveDeploymentQuery(ctx context.Context, uri ResourceUri, outputFormat string) (string, error) {

Review Comment:
   So, if you can't find the service, you try to find the pod assuming that there's only one pod in the deployment as a fallback? I think it's safer to just fail and not assume that. Otherwise, we might see weird behaviors in the service connectivity. Also, we can add this to the docs saying that a Deployment must have a Service.



##########
controllers/discovery/discovery.go:
##########
@@ -57,6 +59,7 @@ type ResourceUri struct {
 	GVK          v1.GroupVersionKind
 	Namespace    string
 	Name         string
+	Port         string

Review Comment:
   Is this only valid for Services and Containers? We might have to add this to a specific struct or have a custom query attribute here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] kie-issues-308: Operator driven service discovery API Phase2 [incubator-kie-kogito-serverless-operator]

Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on code in PR #309:
URL: https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/309#discussion_r1402689331


##########
controllers/discovery/kubernetes_catalog.go:
##########
@@ -58,21 +72,97 @@ func (c k8sServiceCatalog) resolveServiceQuery(ctx context.Context, uri Resource
 }
 
 func (c k8sServiceCatalog) resolvePodQuery(ctx context.Context, uri ResourceUri, outputFormat string) (string, error) {
-	if pod, service, err := findPodAndReferenceServiceByPodLabels(ctx, c.Client, uri.Namespace, uri.Name); err != nil {
+	if pod, serviceList, err := findPodAndReferenceServices(ctx, c.Client, uri.Namespace, uri.Name); err != nil {
 		return "", err
 	} else {
-		if service != nil {
-			if serviceUri, err := resolveServiceUri(service, uri.GetPort(), outputFormat); err != nil {
+		if serviceList != nil && len(serviceList.Items) > 0 {
+			referenceService := selectBestSuitedServiceByCustomLabels(serviceList, uri.CustomLabels)
+			return resolveServiceUri(referenceService, uri.GetPort(), outputFormat)
+		} else {
+			return resolvePodUri(pod, "", uri.GetPort(), outputFormat)
+		}
+	}
+}
+
+func (c k8sServiceCatalog) resolveDeploymentQuery(ctx context.Context, uri ResourceUri, outputFormat string) (string, error) {

Review Comment:
   After re-reading... myself :) , yeah, we should go with Proposal2, at least for the Deployment. Since the ReplicaSet associated with the deployment don't warrant that only one pod instance will be created even in the case where you set the replicas == 1, and we might face situations where 2 pods can be around (at least for a period of time).
   
   wdyt?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] kie-issues-308: Operator driven service discovery API Phase2 [incubator-kie-kogito-serverless-operator]

Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on PR #309:
URL: https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/309#issuecomment-1822890991

   Closes: apache/incubator-kie-kogito-serverless-operator#308


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] kie-issues-308: Operator driven service discovery API Phase2 [incubator-kie-kogito-serverless-operator]

Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on code in PR #309:
URL: https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/309#discussion_r1402679834


##########
controllers/discovery/kubernetes_catalog.go:
##########
@@ -58,21 +72,97 @@ func (c k8sServiceCatalog) resolveServiceQuery(ctx context.Context, uri Resource
 }
 
 func (c k8sServiceCatalog) resolvePodQuery(ctx context.Context, uri ResourceUri, outputFormat string) (string, error) {
-	if pod, service, err := findPodAndReferenceServiceByPodLabels(ctx, c.Client, uri.Namespace, uri.Name); err != nil {
+	if pod, serviceList, err := findPodAndReferenceServices(ctx, c.Client, uri.Namespace, uri.Name); err != nil {
 		return "", err
 	} else {
-		if service != nil {
-			if serviceUri, err := resolveServiceUri(service, uri.GetPort(), outputFormat); err != nil {
+		if serviceList != nil && len(serviceList.Items) > 0 {
+			referenceService := selectBestSuitedServiceByCustomLabels(serviceList, uri.CustomLabels)
+			return resolveServiceUri(referenceService, uri.GetPort(), outputFormat)
+		} else {
+			return resolvePodUri(pod, "", uri.GetPort(), outputFormat)
+		}
+	}
+}
+
+func (c k8sServiceCatalog) resolveDeploymentQuery(ctx context.Context, uri ResourceUri, outputFormat string) (string, error) {

Review Comment:
   We can change if we believe that we have a better option, no problem, but let's double check.
   
   Let me explain the calculation:
   
   1) we have a service, all good, we use it.
   
   2) No service is defined? 
   Ok, we try to pick a pod, but not assuming there is one, we do several checks instead, look:
   
   No replicas ? deployment.Spec.Replicas == nil || *deployment.Spec.Replicas == 0 
   we return a proper message.
   
   Too many replicas:  *deployment.Spec.Replicas > 1
   we return a proper message.
   
   Only one replica?
   good!, we first try to find the corresponding ReplicaSet object, and if found, we double check again how many pods exists, if it has 0, 1, or > 1 pods.
   
   If no pods, or too many pods, we return a proper message.
   
   Only if one pod exists, then we return the corresponding pod address.
   
   The criteria was borrowed from this diagram:
   
   ![sw-discovery-flow](https://github.com/apache/incubator-kie-kogito-serverless-operator/assets/2431454/1ae938f1-7163-4115-8750-3ba57a467a70)
   
   
   
   So we basically do several checks, and only returns a pod if only one pod is present.
   I think it's a matter of how we define the semantic of the service discovery, and here is where we can revisit it.
   
   From the service discovery perspective, what does it mean to access a Deployment?
   
   **Proposal 1)** is what we have, i.e., access to it with the Service is resent, or with the Pod, only if we have one pod etc.
   Does it make sense?
   **Pros:** A Deployment object might exists without an associated object, so from this point of view, it make sense.
   
   **Cons:** It can be argued that the solution is kind of limited, since only deployments with only one pod can be accessed with the service discovery if no service is present. Additionally, a Pod can go down at any time.
   
   **Proposal 2)** we look for the Service, if we find it, all good, if not, ok, we throw an error saying that no Service was found. This basically changes a bit the semantic.
   **Pros:** with the service, the associated pods can go up and down at any time, the service always resolves how to pick one for a given request.
   
   **Cons:** Well, if no service, no access. But it can be fair assumption considering that having service is a recommended practice.
   
   If we go with Proposal 2), we might probably need to apply same criteria for the StatefulSet?, or, in the case of the stateful set, in the case of only 1 replica, we might return **always** the corresponding dns name of the corresponding pod (no chance to return the IP), something like this:  **stateful-set-example-pod-0.stateful-set-example.test-discovery.svc.cluster.local:8080**
   In the end, this DNS name, in cases we have 1 pod, will never change, so, if pod goes down at any time, when restarted, the name DNS name will resolve the instance name.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] kie-issues-308: Operator driven service discovery API Phase2 [incubator-kie-kogito-serverless-operator]

Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on code in PR #309:
URL: https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/309#discussion_r1403389838


##########
controllers/discovery/kubernetes_catalog.go:
##########
@@ -58,21 +72,97 @@ func (c k8sServiceCatalog) resolveServiceQuery(ctx context.Context, uri Resource
 }
 
 func (c k8sServiceCatalog) resolvePodQuery(ctx context.Context, uri ResourceUri, outputFormat string) (string, error) {
-	if pod, service, err := findPodAndReferenceServiceByPodLabels(ctx, c.Client, uri.Namespace, uri.Name); err != nil {
+	if pod, serviceList, err := findPodAndReferenceServices(ctx, c.Client, uri.Namespace, uri.Name); err != nil {
 		return "", err
 	} else {
-		if service != nil {
-			if serviceUri, err := resolveServiceUri(service, uri.GetPort(), outputFormat); err != nil {
+		if serviceList != nil && len(serviceList.Items) > 0 {
+			referenceService := selectBestSuitedServiceByCustomLabels(serviceList, uri.CustomLabels)
+			return resolveServiceUri(referenceService, uri.GetPort(), outputFormat)
+		} else {
+			return resolvePodUri(pod, "", uri.GetPort(), outputFormat)
+		}
+	}
+}
+
+func (c k8sServiceCatalog) resolveDeploymentQuery(ctx context.Context, uri ResourceUri, outputFormat string) (string, error) {

Review Comment:
   Yup, +1 for proposal 2. I think this diagram would make sense for runtimes, but not at the operator level. We can even review this diagram and add the constraint there since the guide should be relocated to Cloud > Operator.
   
   Anyhow, it's too complex to try to "guess" if a deployment has a pod available or not, too many variables that can vary (😢 ), no service, no discovery. Same for the StatefulSet. 👍 



##########
controllers/discovery/kubernetes_catalog.go:
##########
@@ -58,21 +72,97 @@ func (c k8sServiceCatalog) resolveServiceQuery(ctx context.Context, uri Resource
 }
 
 func (c k8sServiceCatalog) resolvePodQuery(ctx context.Context, uri ResourceUri, outputFormat string) (string, error) {
-	if pod, service, err := findPodAndReferenceServiceByPodLabels(ctx, c.Client, uri.Namespace, uri.Name); err != nil {
+	if pod, serviceList, err := findPodAndReferenceServices(ctx, c.Client, uri.Namespace, uri.Name); err != nil {
 		return "", err
 	} else {
-		if service != nil {
-			if serviceUri, err := resolveServiceUri(service, uri.GetPort(), outputFormat); err != nil {
+		if serviceList != nil && len(serviceList.Items) > 0 {
+			referenceService := selectBestSuitedServiceByCustomLabels(serviceList, uri.CustomLabels)
+			return resolveServiceUri(referenceService, uri.GetPort(), outputFormat)
+		} else {
+			return resolvePodUri(pod, "", uri.GetPort(), outputFormat)
+		}
+	}
+}
+
+func (c k8sServiceCatalog) resolveDeploymentQuery(ctx context.Context, uri ResourceUri, outputFormat string) (string, error) {

Review Comment:
   Yup, +1 for proposal 2. I think this diagram would make sense for runtimes, but not at the operator level. We can even review this diagram and add the constraint there since the guide should be relocated to Cloud > Operator.
   
   Anyhow, it's too complex to try to "guess" if a deployment has a pod available or not, too many variables that can vary (😢 ), no service, no discovery. Same for the StatefulSet. 👍 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org