Giter VIP home page Giter VIP logo

Comments (8)

sttts avatar sttts commented on July 18, 2024 2

If you add a type to a scheme, its Go type name is used as kind (via reflection).

Now I also understand what is going on. You are getting a CronTab from the server and the client tries to find a CronTab in its scheme. It only finds a Crontab, which is not helpful. So the server returns an unexpected object. Those two have to match.

Where Crontab is added to the scheme in register.go, you can give a custom name with the capital T. Then it will work too.

from cnat.

yang-wang11 avatar yang-wang11 commented on July 18, 2024 1

@sttts @mhausenblas thanks for the help. it works.

from cnat.

mhausenblas avatar mhausenblas commented on July 18, 2024

Thanks for raising this @yang-wang11 and I'm unsure I follow what exactly your steps were. You mentioned generate-groups.sh (I assume you're referring to https://github.com/kubernetes/code-generator?) Maybe @sttts has a better view?

from cnat.

yang-wang11 avatar yang-wang11 commented on July 18, 2024

@mhausenblas @sttts yes, I follow the book step by step(chapter 4-5). I did the following changes:

  1. upgrade to v1 instead of v1alpha1 for CRD
  2. remove the sub-resource status for CRD

you may see below code generated from generate-groups.sh, it seems to look good.

var Scheme = runtime.NewScheme()
var Codecs = serializer.NewCodecFactory(Scheme)
var ParameterCodec = runtime.NewParameterCodec(Scheme)
var localSchemeBuilder = runtime.SchemeBuilder{
	stablev1.AddToScheme,
}
var AddToScheme = localSchemeBuilder.AddToScheme

func init() {
	v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
	utilruntime.Must(AddToScheme(Scheme))
}

I tried to force execute its init function. the error does seem not to disappear.

_ "typedClient/client/clientset/versioned/scheme"

from cnat.

sttts avatar sttts commented on July 18, 2024

Note the different spelling: CronTab vs. Crontab. The scheme has the latter, the clients wants the former.

from cnat.

sttts avatar sttts commented on July 18, 2024

no kind "CronTab" is registered for version "stable.example.com/v1" in scheme "pkg/crd/typedClient/client/clientset/versioned/scheme/register.go:15"

Is this a copy-and-pasted error message? Am not sure where client-gen gets the CronTab type from. It is based on the Go type, not the CRD yaml. Hence, it should print a "Crontab" error, not "CronTab" 🤔

from cnat.

yang-wang11 avatar yang-wang11 commented on July 18, 2024

@sttts thanks for the help.
I'm a little confused, is that mean I need to rename my go type from Crontab to CronTab? like below

func addKnownTypes(scheme *runtime.Scheme) error {
	scheme.AddKnownTypes(SchemeGroupVersion,
		&CronTabList{},
		&CronTab{},
	)
	metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
	return nil
}

from cnat.

yang-wang11 avatar yang-wang11 commented on July 18, 2024

no kind "CronTab" is registered for version "stable.example.com/v1" in scheme "pkg/crd/typedClient/client/clientset/versioned/scheme/register.go:15"

Is this a copy-and-pasted error message? Am not sure where client-gen gets the CronTab type from. It is based on the Go type, not the CRD yaml. Hence, it should print a "Crontab" error, not "CronTab" 🤔

yes, this error message copy from the console.

from cnat.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.