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

Assign predefined clustersetIP to service status #1

Conversation

andrewsykim
Copy link
Member

@andrewsykim andrewsykim commented Aug 11, 2020

This PR updates the current demo to to set Service.Status.LoadBalancer if clusterset IPs is predefined in ServiceImport.

This allows the implementation to rely on clusterIP for ServiceImport.Spec.IPs or pre-allocate a well known IP for the clustersetIP.

Signed-off-by: Andrew Sy Kim kim.andrewsy@gmail.com

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 11, 2020
@andrewsykim
Copy link
Member Author

/assign @JeremyOT

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 11, 2020
@andrewsykim andrewsykim force-pushed the clusterset-ip-from-service-import branch from dee79d8 to 9254864 Compare August 11, 2020 15:33
@andrewsykim
Copy link
Member Author

andrewsykim commented Aug 11, 2020

Some manual validation running the demo script:

$ kubectl --kubeconfig scripts/c1.kubeconfig -n demo get serviceimports
NAME    TYPE           IP          AGE
serve   ClusterSetIP   [1.2.3.4]   13m
$
$ kubectl --kubeconfig scripts/c1.kubeconfig -n demo get svc
NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
derived-ovtkn0laet   ClusterIP   10.11.78.176   <none>        80/TCP    2m36s
serve                ClusterIP   10.11.174.93   <none>        80/TCP    2m49s
$ 
$ kubectl --kubeconfig scripts/c1.kubeconfig -n demo get svc derived-ovtkn0laet -o yaml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2020-08-11T15:22:26Z"
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:ownerReferences:
          .: {}
          k:{"uid":"edd5dedb-5ee7-4b57-8c91-9654bff70449"}:
            .: {}
            f:apiVersion: {}
            f:kind: {}
            f:name: {}
            f:uid: {}
      f:spec:
        f:ports:
          .: {}
          k:{"port":80,"protocol":"TCP"}:
            .: {}
            f:port: {}
            f:protocol: {}
            f:targetPort: {}
        f:sessionAffinity: {}
        f:type: {}
      f:status:
        f:loadBalancer:
          f:ingress: {}
    manager: controller
    operation: Update
    time: "2020-08-11T15:22:26Z"
  name: derived-ovtkn0laet
  namespace: demo
  ownerReferences:
  - apiVersion: multicluster.x-k8s.io/v1alpha1
    kind: ServiceImport
    name: serve
    uid: edd5dedb-5ee7-4b57-8c91-9654bff70449
  resourceVersion: "688"
  selfLink: /api/v1/namespaces/demo/services/derived-ovtkn0laet
  uid: a502033b-aab5-491d-8b7f-25a5ff32b3f6
spec:
  clusterIP: 10.11.78.176
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer:
    ingress:
    - ip: 1.2.3.4

Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>
@andrewsykim andrewsykim force-pushed the clusterset-ip-from-service-import branch from 9254864 to 3c023fb Compare August 11, 2020 18:09
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 11, 2020
@andrewsykim andrewsykim changed the title Assume clustersetIP is provided from ServiceImport Assign predefined clustersetIP to service status Aug 11, 2020
Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>
@andrewsykim
Copy link
Member Author

Based on some conversations with @JeremyOT , I've updated the PR so that we add IPs to service status if a clustersetIP is predefined. Otherwise we continue to put clusterIP into ServiceImport.Spec.IPs

$ kubectl --kubeconfig ./scripts/c1.kubeconfig get serviceimport -A
NAMESPACE   NAME             TYPE           IP                AGE
demo        serve            ClusterSetIP   [10.11.104.125]   2m6s
demo        serve-with-vip   ClusterSetIP   [1.2.3.4]         2m5s

@@ -114,6 +118,29 @@ func (r *ServiceImportReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
return ctrl.Result{}, err
}
log.Info("created service")

if len(svcImport.Spec.IPs) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

It's a small chance, but it seems like we want to verify the current state of the Service as well. As is, if the status update were to fail, we'd see the existing service on the next iteration and never set the LB IP. Since the updated Service controller ignores an import with a pre-existing IP, we wouldn't reconcile from the other side either

Copy link
Member Author

Choose a reason for hiding this comment

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

I had the same thought as I was writing this initially 🤔

I agree with you, but I think that would require a larger refactor of this controller since we only reconcile the Service if it doesn't exist (based on line 93 - 97). So if the Service already exists, we would return early and never attempt to reconcile the status anyways. Was actually planning on adding the "update if already exists" logic for Services in a follow-up PR but I can do it here if you prefer.

@JeremyOT
Copy link
Member

Thanks for this!

@JeremyOT
Copy link
Member

JeremyOT commented Sep 8, 2020

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 8, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewsykim, JeremyOT

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 8, 2020
@k8s-ci-robot k8s-ci-robot merged commit d261767 into kubernetes-sigs:master Sep 8, 2020
k8s-ci-robot added a commit that referenced this pull request Nov 28, 2022
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants