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

code-gen not building out client fully with interfaces #124

Closed
michelleN opened this issue Apr 14, 2021 · 1 comment
Closed

code-gen not building out client fully with interfaces #124

michelleN opened this issue Apr 14, 2021 · 1 comment

Comments

@michelleN
Copy link

michelleN commented Apr 14, 2021

➜  smi-sdk git:(main) ✗ ./hack/update-codegen.sh
>>> using codegen: /Users/<user>/go/pkg/mod/k8s.io/code-generator@v0.19.2
##### Generating split.smi-spec.io client ######
Generating clientset for split:v1alpha1 at github.com/<user>/smi-sdk/pkg/gen/client/split/clientset
2021/04/14 11:46:18 gopathwalk: scanning directory /Users/<user>/go/pkg/mod/github.com/googleapis/gnostic@v0.5.1: open /Users/<user>/go/pkg/mod/github.com/googleapis/gnostic@v0.5.1/plugins/gnostic-complexity: interrupted system call
2021/04/14 11:46:18 gopathwalk: scanning directory /Users/<user>/go/pkg/mod: open /Users/<user>/go/pkg/mod/github.com/!microsoft/go-winio@v0.4.15-0.20190919025122-fc70bd9a86b5/backuptar: interrupted system call

My script is:

#!/usr/bin/env bash

# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

ROOT_PACKAGE="github.com/michelleN/smi-sdk"
ROOT_DIR="$(git rev-parse --show-toplevel)"


# get code-generator version from go.sum
CODEGEN_VERSION="v0.19.2" # Must match k8s.io/client-go version defined in go.mod
CODEGEN_PKG="$(echo `go env GOPATH`/pkg/mod/k8s.io/code-generator@${CODEGEN_VERSION})"

echo ">>> using codegen: ${CODEGEN_PKG}"
# ensure we can execute the codegen script
chmod +x ${CODEGEN_PKG}/generate-groups.sh

function generate_client() {
  CUSTOM_RESOURCE_NAME=$1
  CUSTOM_RESOURCE_VERSIONS=$2

   # code-generator makes assumptions about the project being located in `$GOPATH/src`.

  "${CODEGEN_PKG}"/generate-groups.sh all \
    "$ROOT_PACKAGE/generated/$CUSTOM_RESOURCE_NAME" \
    "$ROOT_PACKAGE/apis" \
    $CUSTOM_RESOURCE_NAME:$CUSTOM_RESOURCE_VERSIONS \
    --go-header-file "${ROOT_DIR}"/hack/boilerplate.go.txt \
    --output-base ../../../ -v 10
}

echo "##### Generating split.smi-spec.io client ######"
generate_client "split" "v1alpha1"

My directory structure looks like this:
Screen Shot 2021-04-14 at 12 22 43 PM

This is what gets generated:
Screen Shot 2021-04-14 at 12 23 17 PM

generated/split/clientset/versioned/typed/split/v1alpha1/split_client.go and generated/split/clientset/versioned/typed/split/v1alpha1/generated_expansion.go are both empty.

While clientset.go looks like this

➜  smi-sdk git:(main) ✗ cat generated/split/clientset/versioned/clientset.go
/*
Copyright 2021.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by client-gen. DO NOT EDIT.

package versioned

import (
	"fmt"

	splitv1alpha1 "github.com/michelleN/smi-sdk/generated/split/clientset/versioned/typed/split/v1alpha1"
	discovery "k8s.io/client-go/discovery"
	rest "k8s.io/client-go/rest"
	flowcontrol "k8s.io/client-go/util/flowcontrol"
)

type Interface interface {
	Discovery() discovery.DiscoveryInterface
	SplitV1alpha1() splitv1alpha1.SplitV1alpha1Interface
}

// Clientset contains the clients for groups. Each group has exactly one
// version included in a Clientset.
type Clientset struct {
	*discovery.DiscoveryClient
	splitV1alpha1 *splitv1alpha1.SplitV1alpha1Client
}
[...]

References to the interfaces show this error:

SplitV1alpha1Interface not declared by package v1alpha1 compilerUndeclaredImportedName
@michelleN
Copy link
Author

Turns out I was just missing the genclient marker. It's no longer required by kube builder so I thought it was deprecated here too. 🤦

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

1 participant