Skip to content

Commit

Permalink
Merge pull request #211 from Abirdcfly/main
Browse files Browse the repository at this point in the history
feat: add client,lister,informer for bc-explorer
  • Loading branch information
bjwswang authored Mar 24, 2023
2 parents d717b9e + ddb11cf commit d879467
Show file tree
Hide file tree
Showing 92 changed files with 8,035 additions and 19 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Verify

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
verify:
name: verify
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Set up Go command
uses: actions/setup-go@v4
with:
go-version: 'stable'
check-latest: true
- name: verify codegen
run: hack/verify-codegen.sh

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Temporary Build Files
build/_output
build/_test
_output
# Created by https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
### Emacs ###
# -*- mode: gitignore; -*-
Expand Down
2 changes: 2 additions & 0 deletions api/v1beta1/chaincode_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const (
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,shortName=cc
// +genclient
// +genclient:nonNamespaced
type Chaincode struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
9 changes: 5 additions & 4 deletions api/v1beta1/chaincodebuild_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ type ChaincodeBuildStatus struct {
PipelineRunResults []pipelinev1beta1.PipelineRunResult `json:"pipelineResults,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,shortName=ccb;ccbs

// +genclient
// +genclient:nonNamespaced
// ChaincodeBuild is the Schema for the chaincodebuilds API
type ChaincodeBuild struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -103,7 +104,7 @@ type ChaincodeBuild struct {
Status ChaincodeBuildStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// ChaincodeBuildList contains a list of ChaincodeBuild
type ChaincodeBuildList struct {
Expand Down
9 changes: 5 additions & 4 deletions api/v1beta1/channel_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ type ChannelStatus struct {
PeerConditions []PeerCondition `json:"peerConditions,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,shortName=chan;chans

// +genclient
// +genclient:nonNamespaced
// Channel is the Schema for the channels API
type Channel struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -90,7 +91,7 @@ type Channel struct {
Status ChannelStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// ChannelList contains a list of Channel
type ChannelList struct {
Expand Down
21 changes: 21 additions & 0 deletions api/v1beta1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2016 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.
*/

// +k8s:deepcopy-gen=package
// +k8s:defaulter-gen=TypeMeta
// +groupName=ibp.com

package v1beta1 // import "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
2 changes: 2 additions & 0 deletions api/v1beta1/endorsepolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,shortName=epolicy;epolicies
// +genclient
// +genclient:nonNamespaced
type EndorsePolicy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
5 changes: 3 additions & 2 deletions api/v1beta1/federation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type FederationStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,shortName=fed;feds
// +genclient
// +genclient:nonNamespaced
// Federation is the Schema for the federations API
type Federation struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -75,8 +77,7 @@ type Federation struct {
Status FederationStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// +kubebuilder:object:root=true
// FederationList contains a list of Federation
type FederationList struct {
metav1.TypeMeta `json:",inline"`
Expand Down
16 changes: 15 additions & 1 deletion api/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,27 @@ import (
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

const (
GroupName = "ibp.com"
Version = "v1beta1"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "ibp.com", Version: "v1beta1"}
GroupVersion = schema.GroupVersion{Group: GroupName, Version: Version}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme

// SchemeGroupVersion is group version used to register these objects
// Deprecated: use GroupVersion instead.
SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: Version}
)

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
1 change: 1 addition & 0 deletions api/v1beta1/ibpca_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ type IBPCAStatus struct {
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`IBPPeer,v1beta1,""`
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`IBPOrderer,v1beta1,""`
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`IBPConsole,v1beta1,""`
// +genclient
type IBPCA struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/ibpconsole_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ type IBPConsoleStatus struct {
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`IBPPeer,v1beta1,""`
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`IBPOrderer,v1beta1,""`
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`IBPConsole,v1beta1,""`
// +genclient
type IBPConsole struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/ibporderer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ type IBPOrdererStatus struct {
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`IBPPeer,v1beta1,""`
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`IBPOrderer,v1beta1,""`
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`IBPConsole,v1beta1,""`
// +genclient
type IBPOrderer struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/ibppeer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ type IBPPeerStatus struct {
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`IBPOrderer,v1beta1,""`
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`IBPConsole,v1beta1,""`
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`clusterversions,v1,""`
// +genclient
type IBPPeer struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
30 changes: 30 additions & 0 deletions api/v1beta1/install/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright contributors to the Hyperledger Fabric Operator project
*
* SPDX-License-Identifier: Apache-2.0
*
* 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.
*/

package install

import (
"github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
)

// Install registers the API group and adds types to a scheme
func Install(scheme *runtime.Scheme) {
utilruntime.Must(v1beta1.AddToScheme(scheme))
}
5 changes: 3 additions & 2 deletions api/v1beta1/network_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type NetworkStatus struct {
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// Network is the Schema for the networks API
// +genclient
// +genclient:nonNamespaced
type Network struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -64,8 +66,7 @@ type Network struct {
Status NetworkStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// +kubebuilder:object:root=true
// NetworkList contains a list of Network
type NetworkList struct {
metav1.TypeMeta `json:",inline"`
Expand Down
12 changes: 6 additions & 6 deletions api/v1beta1/organization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ type OrganizationStatus struct {
Federations []string `json:"federations,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster,shortName=org;orgs

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,shortName=org;orgs
// +genclient
// +genclient:nonNamespaced
// Organization is the Schema for the organizations API
type Organization struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -77,8 +78,7 @@ type Organization struct {
Status OrganizationStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// +kubebuilder:object:root=true
// OrganizationList contains a list of Organization
type OrganizationList struct {
metav1.TypeMeta `json:",inline"`
Expand Down
2 changes: 2 additions & 0 deletions api/v1beta1/proposal_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const (
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,shortName=pro;pros
// +genclient
// +genclient:nonNamespaced
type Proposal struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/vote_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
// +k8s:deepcopy-gen=true
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +genclient
type Vote struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
33 changes: 33 additions & 0 deletions hack/lib/golang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

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

function go::create_gopath_tree() {
local go_pkg_dir="${BUILD_GOPATH}/src/${PACKAGE_NAME}"
local go_pkg_basedir
go_pkg_basedir=$(dirname "${go_pkg_dir}")

mkdir -p "${go_pkg_basedir}"

if [[ ! -e ${go_pkg_dir} || "$(readlink "${go_pkg_dir}")" != "${ROOT_PATH}" ]]; then
ln -snf "${ROOT_PATH}" "${go_pkg_dir}"
fi
}

function go::setup_env() {
go::create_gopath_tree

export GOPATH="${BUILD_GOPATH}"
export GOCACHE="${BUILD_GOPATH}/cache"

export PATH="${BUILD_GOPATH}/bin:${PATH}"

GOROOT=$(go env GOROOT)
export GOROOT

unset GOBIN

cd "$BUILD_GOPATH/src/$PACKAGE_NAME"
}
9 changes: 9 additions & 0 deletions hack/lib/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

unset CDPATH

ROOT_PATH=$(git rev-parse --show-toplevel)
readonly PACKAGE_NAME="github.com/IBM-Blockchain/fabric-operator"
readonly OUTPUT_DIR="${ROOT_PATH}/_output"
readonly BUILD_GOPATH="${OUTPUT_DIR}/go"
source "${ROOT_PATH}/hack/lib/golang.sh"
46 changes: 46 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

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

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${SCRIPT_ROOT}/hack/lib/init.sh"
go::setup_env
cd "${ROOT_PATH}"

echo "codegen start."
echo "tools install..."

GENERATOR_VERSION=${GENERATOR_VERSION:-$(cat "${ROOT_PATH}"/go.mod | grep "k8s.io/code-generator" | awk '{print $2}')}
GO111MODULE=on go install k8s.io/code-generator/cmd/client-gen@${GENERATOR_VERSION}
GO111MODULE=on go install k8s.io/code-generator/cmd/lister-gen@${GENERATOR_VERSION}
GO111MODULE=on go install k8s.io/code-generator/cmd/informer-gen@${GENERATOR_VERSION}

echo "Generating with client-gen..."
client-gen \
--go-header-file hack/boilerplate.go.txt \
--input-base="github.com/IBM-Blockchain/fabric-operator/api" \
--input="v1beta1" \
--output-package=github.com/IBM-Blockchain/fabric-operator/pkg/generated/clientset \
--clientset-name=versioned

echo "Generating with lister-gen..."
lister-gen \
--go-header-file hack/boilerplate.go.txt \
--input-dirs=github.com/IBM-Blockchain/fabric-operator/api/v1beta1 \
--output-package=github.com/IBM-Blockchain/fabric-operator/pkg/generated/listers

echo "Generating with informer-gen..."
informer-gen \
--go-header-file hack/boilerplate.go.txt \
--input-dirs=github.com/IBM-Blockchain/fabric-operator/api/v1beta1 \
--versioned-clientset-package=github.com/IBM-Blockchain/fabric-operator/pkg/generated/clientset/versioned \
--listers-package=github.com/IBM-Blockchain/fabric-operator/pkg/generated/listers \
--output-package=github.com/IBM-Blockchain/fabric-operator/pkg/generated/informers

# FIXME: this may be fixed by set right arg in client-gen or informer-gen ?
find pkg/generated/informers -type f -exec sed -i.bak 's/IbpV1beta1/Ibp/g' {} +
find pkg/generated/informers -type f -name '*.bak' -delete

echo "codegen done."
Loading

0 comments on commit d879467

Please sign in to comment.