https://pulumi.com logo
#kubernetes
Title
# kubernetes
b

bitter-application-91815

10/08/2020, 11:23 AM
Is there any api for this ?
g

gorgeous-egg-16927

10/08/2020, 5:25 PM
I’m not seeing it in our API docs for some reason, but each resource includes a
.get
method that can be used to read resource state. Something like
k8s.networking.v1.Ingress.get('existingResource', 'axiomdb/myIngress')
should do the trick
b

bitter-application-91815

10/09/2020, 7:35 PM
Thanks Levi, but i'm looking at the go api here
same for Ingress.go
Copy code
func GetIngressList(ctx *pulumi.Context,
	name string, id pulumi.IDInput, state *IngressListState, opts ...pulumi.ResourceOption) (*IngressList, error) {
What's the ID here, I created the ingress controller using helm charts so i don't have a resource that has an ID on it
Copy code
// helmchart for ALB
	albResource, err := helm.NewChart(ctx, fmt.Sprintf("axiom-alb-charts-%s", w.targetEnv), helm.ChartArgs{
		Chart:     pulumi.String("aws-alb-ingress-controller"),
		Namespace: pulumi.String(namespace),
		FetchArgs: helm.FetchArgs{
			Repo: pulumi.String("<http://storage.googleapis.com/kubernetes-charts-incubator>"),
		},
		Values: pulumi.Map{
			"clusterName": w.eksCluster.Name,
			"awsVpcID":    w.vpNetwork.ID(),
			"awsRegion":   pulumi.String(os.Getenv(PrimaryRegion)),
		},
	}, pulumi.Provider(k8sProvider))
	if err != nil {
		return err
	}

	/*for _, r := range albResource.Resources {
	}*/

	ingress, err := networking.GetIngress(ctx, fmt.Sprintf("axiom-alb-charts-%s", w.targetEnv), albResource.Resources.ID(), nil)
	if err != nil {
		return err
	}
g

gorgeous-egg-16927

10/09/2020, 8:24 PM
The id is of the form
[namespace]/name
, where name is the name of the actual k8s resource that you would see with
kubectl get ing
b

bitter-application-91815

10/09/2020, 8:48 PM
So i tried this
Copy code
ingress, err := networking.GetIngress(ctx, "axiomdb-ingress", pulumi.IDInput(pulumi.ID(fmt.Sprintf("%s/axiomdb-ingress", namespace))), nil)
	if err != nil {
		return err
	}
	ctx.Export("axiomDBIngress", ingress.Kind)
Copy code
Type                                         Name                                               Plan       Info
     pulumi:pulumi:Stack                          staging-axiom-cloud                                           1 error
 ~   ├─ aws:ec2:RouteTable                        axiom-cloud-private-subnet-2-routetable-staging-g  update     [diff: ~routes]
 ~   ├─ aws:ec2:RouteTable                        axiom-cloud-private-subnet-3-routetable-staging-g  update     [diff: ~routes]
 ~   ├─ aws:ec2:RouteTable                        axiom-cloud-private-subnet-1-routetable-staging-g  update     [diff: ~routes]
     ├─ kubernetes:<http://helm.sh/v3:Chart|helm.sh/v3:Chart>               axiomdb-charts-staging-g                                      
     │  └─ kubernetes:extensions/v1beta1:Ingress  axiomdb/axiomdb-ingress                                       1 warning
     └─ kubernetes:<http://networking.k8s.io/v1:Ingress|networking.k8s.io/v1:Ingress>   axiomdb-ingress                                               1 error
 
Diagnostics:
  kubernetes:extensions/v1beta1:Ingress (axiomdb/axiomdb-ingress):
    warning: extensions/v1beta1/Ingress is deprecated by <http://networking.k8s.io/v1beta1/Ingress|networking.k8s.io/v1beta1/Ingress> and not supported by Kubernetes v1.20+ clusters.
 
  kubernetes:<http://networking.k8s.io/v1:Ingress|networking.k8s.io/v1:Ingress> (axiomdb-ingress):
    error: Preview failed: resource 'axiomdb/axiomdb-ingress' does not exist
 
  pulumi:pulumi:Stack (staging-axiom-cloud):
    error: preview failed
 

ronoc@gunther:~/source/watchly/service/cloud/aws/staging$ kubectl get ing -A
NAMESPACE   NAME              HOSTS   ADDRESS                                                                           PORTS   AGE
axiomdb     axiomdb-ingress   *       <http://internal-2fd8be7b-axiomdb-axiomdbin-0378-1435062635.eu-west-2.elb.amazonaws.com|internal-2fd8be7b-axiomdb-axiomdbin-0378-1435062635.eu-west-2.elb.amazonaws.com>   80      2d9h
ronoc@gunther:~/source/watchly/service/cloud/aws/staging$
I'm a being special 😄 ?
g

gorgeous-egg-16927

10/09/2020, 8:55 PM
Oops, just realized you were trying to get a property of a resource from a Helm chart deployed with Pulumi (I initially thought you meant you had deployed it separately with the Helm CLI). You should be able to use the
GetResource
method on the Chart to get that.
b

bitter-application-91815

10/09/2020, 8:55 PM
and that should have the endpoint ?
g

gorgeous-egg-16927

10/09/2020, 8:56 PM
Yeah. You’ll have to cast it to the Ingress type to access it though. That method returns
AnyOutput
b

bitter-application-91815

10/09/2020, 9:02 PM
So
GetResource(gvk, name, namespace string)
=> GetResource("ingress", "axiomdb-ingress", "axiom")
?
Sorry i'm no K8s expert
g

gorgeous-egg-16927

10/09/2020, 9:05 PM
gvk would be
networking/v1/Ingress
b

bitter-application-91815

10/09/2020, 9:05 PM
Thanks Levi
g

gorgeous-egg-16927

10/09/2020, 9:06 PM
And from the output you pasted, I think the namespace is
axiomdb
b

bitter-application-91815

10/09/2020, 9:29 PM
yep, i'm finding this API pretty obtuse, it doesn't like this caste
r := ingressChart.GetResource("networking/v1/Ingress", "axiomdb-ingress", "axiomdb") if ing, ok := r.(networking.Ingress); ok { }
is that what you meant re casting ?
b

bitter-application-91815

10/09/2020, 9:38 PM
Thanks Levi
g

gorgeous-egg-16927

10/09/2020, 9:38 PM
We really need to add this to the API docs at some point
b

bitter-application-91815

10/09/2020, 9:40 PM
Documentation, the never ending task.
😉 1
Copy code
ingressIP := ingressChart.GetResource("networking/v1/Ingress", "axiomdb-ingress", "axiomdb").
		Apply(func(r interface{}) (interface{}, error) {
			svc := r.(*networking.Ingress)
			return svc.Status.LoadBalancer.Ingress()[0].Hostname, nil
		})
	ctx.Export("ingressIP", ingressIP)
Going by the docs this should work
Copy code
<https://raw.githubusercontent.com/pulumi/pulumi-kubernetes/master/sdk/go/kubernetes/core/v1/pulumiTypes.go>
Copy code
Type                 Name                 Plan     Info
     pulumi:pulumi:Stack  staging-axiom-cloud           1 error; 2 messages
 
Diagnostics:
  pulumi:pulumi:Stack (staging-axiom-cloud):
    # <http://axicode.axiom.co/watchmakers/watchly/service/cloud/aws|axicode.axiom.co/watchmakers/watchly/service/cloud/aws>
    ../eks.go:175:34: svc.Status.LoadBalancer.Ingress undefined (type func() "<http://github.com/pulumi/pulumi-kubernetes/sdk/v2/go/kubernetes/core/v1|github.com/pulumi/pulumi-kubernetes/sdk/v2/go/kubernetes/core/v1>".LoadBalancerStatusPtrOutput has no field or method Ingress)
 
    error: an unhandled error occurred: program exited with non-zero exit code: 2
Apologies for the link to Raw but Github refuses to give me the nice view, the method call i'm trying to use in question is on line 12596
OK sorry I was using the API incorrectly,but here goes
here is my code
Copy code
ingressIP := ingressChart.GetResource("networking/v1/Ingress", "axiomdb-ingress", "axiomdb").
		Apply(func(r interface{}) (interface{}, error) {
			svc := r.(*networking.Ingress)
			return svc.Status.LoadBalancer().Ingress().Index(<http://pulumi.Int|pulumi.Int>(0)).Hostname, nil
		})
	ctx.Export("ingressIP", ingressIP)
Stacktrace
Copy code
panic: interface conversion: interface {} is nil, not *v1.Ingress
    goroutine 316 [running]:
    <http://axicode.axiom.co/watchmakers/watchly/service/cloud/aws.(*worker).buildEks.func1(0x0|axicode.axiom.co/watchmakers/watchly/service/cloud/aws.(*worker).buildEks.func1(0x0>, 0x0, 0x79715c0, 0xc00008aa80, 0xc000501c10, 0x4155f3)
    	/home/ronoc/source/watchly/service/cloud/aws/eks.go:174 +0x10a
    <http://github.com/pulumi/pulumi/sdk/v2/go/pulumi.(*OutputState).Apply.func1(0x909b940|github.com/pulumi/pulumi/sdk/v2/go/pulumi.(*OutputState).Apply.func1(0x909b940>, 0xc000056110, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    	/home/ronoc/.axiom-dev/gopath/pkg/mod/github.com/pulumi/pulumi/sdk/v2@v2.9.2/go/pulumi/types.go:305 +0x39
    reflect.Value.call(0x7930160, 0xc0005bccd0, 0x13, 0x8f07e20, 0x4, 0xc000501f60, 0x2, 0x2, 0xc0003a4ed8, 0x494add, ...)
    	/home/ronoc/.axiom-dev/go/src/reflect/value.go:460 +0x5f6
    reflect.Value.Call(0x7930160, 0xc0005bccd0, 0x13, 0xc0003a4f60, 0x2, 0x2, 0x0, 0x0, 0x1)
    	/home/ronoc/.axiom-dev/go/src/reflect/value.go:321 +0xb4
    <http://github.com/pulumi/pulumi/sdk/v2/go/pulumi.(*OutputState).ApplyTWithContext.func1(0xc00044a5b0|github.com/pulumi/pulumi/sdk/v2/go/pulumi.(*OutputState).ApplyTWithContext.func1(0xc00044a5b0>, 0x909b940, 0xc000056110, 0x90f1860, 0xc00044a620, 0x7930160, 0xc0005bccd0, 0x13)
    	/home/ronoc/.axiom-dev/gopath/pkg/mod/github.com/pulumi/pulumi/sdk/v2@v2.9.2/go/pulumi/types.go:392 +0x23f
    created by <http://github.com/pulumi/pulumi/sdk/v2/go/pulumi.(*OutputState).ApplyTWithContext|github.com/pulumi/pulumi/sdk/v2/go/pulumi.(*OutputState).ApplyTWithContext>
    	/home/ronoc/.axiom-dev/gopath/pkg/mod/github.com/pulumi/pulumi/sdk/v2@v2.9.2/go/pulumi/types.go:380 +0x1e0
    exit status 2
Basically this
svc := r.(*networking.Ingress)
r is nil
Copy code
panic: interface conversion: interface {} is nil, not *v1.Ingress
    goroutine 316 [running]:
g

gorgeous-egg-16927

10/12/2020, 5:10 PM
Can you try changing this line?
Copy code
ingressIP := ingressChart.GetResource("<http://networking.k8s.io/v1/Ingress|networking.k8s.io/v1/Ingress>", "axiomdb-ingress", "axiomdb").
It looks like the id field for the Go SDK is using the fully-qualified Group name (i.e.,
<http://networking.k8s.io|networking.k8s.io>
rather than
networking
)
b

bitter-application-91815

10/12/2020, 6:43 PM
Same again
Copy code
error: an unhandled error occurred: program exited with non-zero exit code: 1
 
    panic: interface conversion: interface {} is nil, not *v1.Ingress
I deleted the chart, and tried to redeploy it to ensure it wasn't some stateful issue
same again
5 Views