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

AtList Sample does not compile #3

Open
DavidLangworthy opened this issue Sep 21, 2019 · 3 comments
Open

AtList Sample does not compile #3

DavidLangworthy opened this issue Sep 21, 2019 · 3 comments

Comments

@DavidLangworthy
Copy link

The AtList sample does not compile. Can you explain how this should work? I fixed up the imports and package names as below but I am getting the following error

dlan@dlan-XPS-13:~/repos/kube/genesys/cnat-client$ go build
# dlan/cnat-client
./main.go:18:14: undefined: client.NewScheme
./main.go:25:55: cannot use client.InNamespace("default") (type client.InNamespace) as type runtime.Object in argument to cl.List:
	client.InNamespace does not implement runtime.Object (missing DeepCopyObject method)
./main.go:25:55: cannot use list (type *v1alpha1.AtList) as type client.ListOption in argument to cl.List:
	*v1alpha1.AtList does not implement client.ListOption (missing ApplyToList method)

Here's the code

package main

import (
	"context"
	"flag"

	"k8s.io/client-go/tools/clientcmd"

	cnatv1alpha1 "github.com/programming-kubernetes/cnat/cnat-kubebuilder/pkg/apis/cnat/v1alpha1"
	runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)

func main() {
	kubeconfig := flag.String("kubeconfig", "~/.kube/config", "kubeconfig file")
	flag.Parse()
	config, _ := clientcmd.BuildConfigFromFlags("", *kubeconfig)

	crScheme := runtimeclient.NewScheme()
	cnatv1alpha1.AddToScheme(crScheme)

	cl, _ := runtimeclient.New(config, runtimeclient.Options{
		Scheme: crScheme,
	})
	list := &cnatv1alpha1.AtList{}
	_ = cl.List(context.TODO(), runtimeclient.InNamespace("default"), list)
}
@benjaminapetersen
Copy link

What page is this? You are prob a bit further along than I am, but I'm happy to look as I've had some experience with other projects. Off the top of my head, the missing DeepCopyObject method looks like a code generation error.

@DavidLangworthy
Copy link
Author

I have the online book so no page numbers. It's toward the end of chapter 4. I've moved on. I just wanted the issue noted for errata.

@benjaminapetersen
Copy link

If you have a fix, do share, for errata/future readers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants