Hey guys. I have some services created by CRD's, a...
# general
m
Hey guys. I have some services created by CRD's, and I would love wait few minutes until they are operational to return their clusterIP. Is there any way to wait for it with pulumi?
Copy code
const service = new k8s.core.v1.Service('rook-ceph-rgw-cluster-object-store', {
      metadata: {
        name: 'rook-ceph-rgw-cluster-object-store',
        namespace: 'rook-ceph'
      }
    }, { parent: this });
I need to wait for this service for few minutes
m
Where and why are you waiting for it? How are you retrieving the cluster IP?
m
I have a service that is being created by rook-ceph operator (out of my control). Unrolling this service takes at least few minutes
So I wrote something like that: import * as pulumi from "@pulumi/pulumi"; import * as k8s from "@pulumi/kubernetes"; export function waitForService( name: string, maxRetries: number = 20, delay: number = 15 ): pulumi.Output<k8s.core.v1.Service> { return pulumi.output(k8s.core.v1.Service.get(name, name)).apply( async () => { let retries = 0; while (retries < maxRetries) { try { const svc = k8s.core.v1.Service.get(name + 'wait_for_service', name); console.log(
Service ${name} is available.
); return svc; } catch (err) { console.log(
Waiting for service ${name}... (Attempt ${retries + 1}/${maxRetries})
); } await new Promise(resolve => setTimeout(resolve, delay * 1000)); retries++; } throw new Error(
Service ${name} was not found within the expected time.
); } ); }
and then in main component resouce I do something like that:
Copy code
this.clusterIP = waitForService('rook-ceph/rook-ceph-rgw-cluster-object-store').apply(s => {
      return s.spec.apply(spec => spec.clusterIP);
    })
m
OK, so you have a service external to your Pulumi program and you need its IP address?
m
yes
m
May I ask why you need this IP address in the first place? Typically, a service is addressed by its name, rather than a (potentially ephemeral) IP address
m
I usually use addresses (*.svc.cluster.local) but in this particular case, I have issue for resolving such addresses with subdomains (like s3bucket-xx.rook-ceph.svc.cluster.local)
m
(Just trying to avoid us solving an XY problem here)
m
It is solving XY problem but I can't help it
m
Well, let's solve the actual problem then. Using the service's IP address will likely cause trouble down the road.
m
Ah It can get changed over time?
Yeah I guess it can
m
At least I don't think there's a guarantee that it remains stable. One point of having a service is that you don't have to deal with IP addresses but can rely on Kubernetes maintaining DNS records for you.
And if you have trouble accessing your service via its name, chances are there's a different problem hiding underneath
m
It is problem underneath, but I really can't solve it, so I tried this workaround
Thank for heads up Kilian
maybe I'll try to solve original issue one more time
👍 1
m
Ah sorry I just debugged that one more time and iT works a bit differently
Copy code
/ # nslookup rook-ceph-rgw-cluster-object-store.rook-ceph.svc.cluster.local
Server:		10.96.0.10
Address:	10.96.0.10:53

Name:	rook-ceph-rgw-cluster-object-store.rook-ceph.svc.cluster.local
Address: 10.103.124.14
Copy code
/ # nslookup rook-ceph-rgw-cluster-object-store.rook-ceph.svc
Server:		10.96.0.10
Address:	10.96.0.10:53

** server can't find rook-ceph-rgw-cluster-object-store.rook-ceph.svc: NXDOMAIN

** server can't find rook-ceph-rgw-cluster-object-store.rook-ceph.svc: NXDOMAIN
m
I don't think the second lookup ever works. If you don't use the FQDN, it's
nslookup rook-ceph-rgw-cluster-object-store.rook-ceph
if you're in a different namespace or
nslookup rook-ceph-rgw-cluster-object-store
if you're in the same namespace
m
It works if I pass IP as s3 endpoint, It stops working if I pass svc.cluster.local address. I bet It's somehow switching from path-style to virtual-hosted style, based on the address I'm passing (ip vs svc.cluster.local)
m
Pretty sure you can solve this by connecting to the service appropriately
m
I will try to debug it on the evening again, thank you sir 🫡
Yeah I was able to test it