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

update groupname for client-gen to logging.kubesphere.io #95

Merged
merged 1 commit into from
Jul 19, 2021
Merged

update groupname for client-gen to logging.kubesphere.io #95

merged 1 commit into from
Jul 19, 2021

Conversation

bojand
Copy link
Member

@bojand bojand commented Jul 16, 2021

While the current implementation of go client generation introduced in #51 seems to work in production fine, there appears to be issues when attempting to use the generated fake package. The issue arises with defaulting to groupName taken from package fluentbitoperator, which results in the fake package defining resource types with that group name:

var inputsResource = schema.GroupVersionResource{Group: "fluentbitoperator", Version: "v1alpha2", Resource: "inputs"}

var inputsKind = schema.GroupVersionKind{Group: "fluentbitoperator", Version: "v1alpha2", Kind: "Input"}

The problem can be simply reproduced by doing something lile:

import (
	...
	"kubesphere.io/fluentbit-operator/api/fluentbitoperator/v1alpha2"
	"kubesphere.io/fluentbit-operator/api/fluentbitoperator/v1alpha2/plugins"
	fbOutput "kubesphere.io/fluentbit-operator/api/fluentbitoperator/v1alpha2/plugins/output"
	fbcs "kubesphere.io/fluentbit-operator/api/generated/clientset/versioned"
	fbopFake "kubesphere.io/fluentbit-operator/api/generated/clientset/versioned/fake"
)
...
func getFake() fbcs.Interface {
	return fbopFake.NewSimpleClientset()
}
...
func doFake() {
	fbopCS := getFake()

	fakeObj := &v1alpha2.Output{
		TypeMeta: metav1.TypeMeta{
			APIVersion: "logging.kubesphere.io/v1alpha2",
			Kind:       "Output",
		},
		ObjectMeta: metav1.ObjectMeta{
			Name:      "fake-output",
			Namespace: "fake-namespace",
			Labels: map[string]string{
				"foo": "bar",
			},
		},
		Spec: v1alpha2.OutputSpec{
			Alias: "output-alias",
			Match: "applogs.foo",
			Syslog: &fbOutput.Syslog{
				Host: "logs.papertrailapp.com",
				Port: ptrInt32(int32(11111)),
				Mode: "tls",
				TLS: &plugins.TLS{
					Verify: ptrBool(true),
				},
			},
		},
	}

	_, err := fbopCS.FluentbitoperatorV1alpha2().Outputs("fake-namespace").Create(context.Background(), fakeObj, metav1.CreateOptions{})

	if err != nil {
		log.Fatalf("creating output: %v", err)
	}

	fmt.Println("fake object:", fakeObj.Name)

	oobj, err := fbopCS.FluentbitoperatorV1alpha2().Outputs("fake-namespace").Get(context.Background(), "fake-output", metav1.GetOptions{})
	if err != nil {
		log.Fatalf("getting output: %v", err)
	}

	fmt.Printf("oobj:\n%+v\n", oobj)

	fakeList, err := fbopCS.FluentbitoperatorV1alpha2().Outputs("fake-namespace").List(context.Background(), metav1.ListOptions{})
	if err != nil {
		log.Fatalf("Error listing all outputs: %v", err)
	}

	fmt.Printf("fakeList:\n%+v\n", fakeList)
}

doFake()

We get error:

2021/07/16 11:22:04 Error listing all outputs: no kind "OutputList" is registered for version "fluentbitoperator/v1alpha2" in scheme "pkg/runtime/scheme.go:100"

With using the code in this PR we now have to use the new top level API:

_, err := fbopCS.LoggingV1alpha2().Outputs("fake-namespace").Create(context.Background(), fakeObj, metav1.CreateOptions{})
	if err != nil {
		log.Fatalf("creating output: %v", err)
	}
...
fakeList, err := fbopCS.LoggingV1alpha2().Outputs("fake-namespace").List(context.Background(), metav1.ListOptions{})
	if err != nil {
		log.Fatalf("Error listing all outputs: %v", err)
	}

and we get the list:

fakeList:
&{TypeMeta:{Kind: APIVersion:} ListMeta:{SelfLink: ResourceVersion: Continue: RemainingItemCount:<nil>} Items:[{TypeMeta:{Kind:Output APIVersion:logging.kubesphere.io/v1alpha2} ObjectMeta:{Name:fake-output GenerateName: Namespace:fake-namespace SelfLink: UID: ResourceVersion: Generation:0 CreationTimestamp:0001-01-01 00:00:00 +0000 UTC DeletionTimestamp:<nil> DeletionGracePeriodSeconds:<nil> Labels:map[foo:bar] Annotations:map[] OwnerReferences:[] Finalizers:[] ClusterName: ManagedFields:[]} Spec:{Match:applogs.foo MatchRegex: Alias:output-alias Elasticsearch:<nil> File:<nil> Forward:<nil> HTTP:<nil> Kafka:<nil> Null:<nil> Stdout:<nil> TCP:<nil> Loki:<nil> Syslog:0xc0004a7ba0}}]}

This is a breaking change in a sense that all previous calls to FluentbitoperatorV1alpha2() will now have to be changed to LoggingV1alpha2(), so this should probably go in a new tag and version.

To my understanding this should no effect manifests and CRD's.

@benjaminhuo benjaminhuo merged commit b7af068 into fluent:master Jul 19, 2021
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

Successfully merging this pull request may close these issues.

3 participants