imawful
imawful

Reputation: 135

Troubleshooting deepcopy-gen not generating deepcopy functions for custom Kubernetes API server

I am trying to create a custom kubernetes api server, and I have defined the types.go file in the directory pkg/apis/baz/v1alpha1,

package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type Foo struct {
    metav1.TypeMeta   `json:",inline"`
    metav1.ObjectMeta `json:"metadata,omitempty"`

    Spec FooSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
}

type FooSpec struct {
    Bar []string `json:"bar" protobuf:"bytes,1,rep,name=bar"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type FooList struct {
    metav1.TypeMeta `json:",inline"`
    metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

    Items []Foo `json:"items" protobuf:"bytes,2,rep,name=items`
}

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type Bar struct {
    metav1.TypeMeta   `json:",inline"`
    metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

    Spec BarSpec
}

type BarSpec struct {
    Description string `json:"description" protobuf:"bytes,1,opt,name=description"`
}

// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type BarList struct {
    metav1.TypeMeta   `json:",inline"`
    metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

    Items []Bar `json:"items" protobuf:"bytes,2,rep,name=items"`
}

I have another types.go file which is for internal types, in the location pkg/apis/baz,

package baz

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type Foo struct {
    metav1.TypeMeta
    metav1.ObjectMeta

    Spec FooSpec
}

type FooSpec struct {
    Bar []FooBar
}

type FooBar struct {
    Name string
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type FooList struct {
    metav1.TypeMeta
    metav1.ListMeta

    Items []Foo
}

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type Bar struct {
    metav1.TypeMeta
    metav1.ObjectMeta

    Spec BarSpec
}

type BarSpec struct {
    // cost is the cost of one instance of this topping.
    Description string
}

I am trying to generate the deepcopy functions for these using deepcopy-gen, I tried running the following command in the directory where deepcopy-gen is located,

./deepcopy-gen --input-dirs "$(PROJECT_ROOT)/pkg/apis/baz/v1alpha1" -O zz_generated.deepcopy

and the same for the internal types with a different location. It doesn't seem to be working, no zz_generated.deepcopy file seems to be created after i run this command. It does not show any error, but the deepcopy functions file is not generated. What am I doing wrong?

Upvotes: 2

Views: 803

Answers (1)

Mykola Kuropatkin
Mykola Kuropatkin

Reputation: 1

I faced the same issue when I was trying to run a command:

deepcopy-gen --input-dirs github.com/NickTaporuk/myresource-crd/pkg/apis/mygroup.example.com/v1alpha1 \
     -O zz_generated.deepcopy \
     --output-base ../../.. \
     -v=8 \
     --go-header-file ./hack/boilerplate.go.txt

I didn't see the file zz_generated.deepcopy.go. And just only when I had deleted package "vendor" from the root directory did this command start working

Upvotes: 0

Related Questions