Skip to content

Commit

Permalink
Generate CodeFlare API client
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti authored and openshift-merge-robot committed Jun 14, 2023
1 parent 360e01f commit 3180604
Show file tree
Hide file tree
Showing 50 changed files with 3,364 additions and 93 deletions.
60 changes: 60 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,38 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: generate-client ## Generate client packages
generate-client: code-generator
rm -rf client
$(APPLYCONFIGURATION_GEN) \
--input-dirs="github.com/project-codeflare/codeflare-operator/api/codeflare/v1alpha1" \
--go-header-file="hack/boilerplate.go.txt" \
--output-package="github.com/project-codeflare/codeflare-operator/client/applyconfiguration" \
--trim-path-prefix "github.com/project-codeflare/codeflare-operator"
$(CLIENT_GEN) \
--input="codeflare/v1alpha1" \
--input-base="github.com/project-codeflare/codeflare-operator/api" \
--apply-configuration-package="github.com/project-codeflare/codeflare-operator/client/applyconfiguration" \
--go-header-file="hack/boilerplate.go.txt" \
--clientset-name "versioned" \
--output-package="github.com/project-codeflare/codeflare-operator/client/clientset" \
--output-base="." \
--trim-path-prefix "github.com/project-codeflare/codeflare-operator"
$(LISTER_GEN) \
--input-dirs="github.com/project-codeflare/codeflare-operator/api/codeflare/v1alpha1" \
--go-header-file="hack/boilerplate.go.txt" \
--output-base="." \
--output-package="github.com/project-codeflare/codeflare-operator/client/listers" \
--trim-path-prefix "github.com/project-codeflare/codeflare-operator"
$(INFORMER_GEN) \
--input-dirs="github.com/project-codeflare/codeflare-operator/api/codeflare/v1alpha1" \
--versioned-clientset-package="github.com/project-codeflare/codeflare-operator/client/clientset/versioned" \
--listers-package="github.com/project-codeflare/codeflare-operator/client/listers" \
--go-header-file="hack/boilerplate.go.txt" \
--output-base="." \
--output-package="github.com/project-codeflare/codeflare-operator/client/informer" \
--trim-path-prefix "github.com/project-codeflare/codeflare-operator"

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
Expand Down Expand Up @@ -185,13 +217,18 @@ $(LOCALBIN):

## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
APPLYCONFIGURATION_GEN ?= $(LOCALBIN)/applyconfiguration-gen
CLIENT_GEN ?= $(LOCALBIN)/client-gen
LISTER_GEN ?= $(LOCALBIN)/lister-gen
INFORMER_GEN ?= $(LOCALBIN)/informer-gen
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
GH_CLI ?= $(LOCALBIN)/gh

## Tool Versions
KUSTOMIZE_VERSION ?= v4.5.4
CODEGEN_VERSION ?= v0.27.2
CONTROLLER_TOOLS_VERSION ?= v0.9.2
OPERATOR_SDK_VERSION ?= v1.27.0
GH_CLI_VERSION ?= 2.30.0
Expand All @@ -213,6 +250,29 @@ $(GH_CLI): $(LOCALBIN)
rm -rf $(GH_CLI_DL_FILENAME)
rm $(GH_CLI_DL_FILENAME).tar.gz

.PHONY: code-generator
code-generator: $(APPLYCONFIGURATION_GEN) $(CLIENT_GEN) $(LISTER_GEN) $(INFORMER_GEN)

.PHONY: applyconfiguration-gen
applyconfiguration-gen: $(APPLYCONFIGURATION_GEN)
$(APPLYCONFIGURATION_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/applyconfiguration-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/applyconfiguration-gen@$(CODEGEN_VERSION)

.PHONY: client-gen
client-gen: $(CLIENT_GEN)
$(CLIENT_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/client-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/client-gen@$(CODEGEN_VERSION)

.PHONY: lister-gen
lister-gen: $(LISTER_GEN)
$(LISTER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/lister-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/lister-gen@$(CODEGEN_VERSION)

.PHONY: informer-gen
informer-gen: $(INFORMER_GEN)
$(INFORMER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/informer-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/informer-gen@$(CODEGEN_VERSION)

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the codeflare v1alpha1 API group
// +k8s:deepcopy-gen=package,register
// +kubebuilder:object:generate=true
// +groupName=codeflare.codeflare.dev
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "codeflare.codeflare.dev", Version: "v1alpha1"}

// 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
)
package v1alpha1
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type InstaScaleStatus struct {
Ready bool `json:"ready"`
}

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

Expand All @@ -80,7 +81,3 @@ type InstaScaleList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []InstaScale `json:"items"`
}

func init() {
SchemeBuilder.Register(&InstaScale{}, &InstaScaleList{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type MCADSpec struct {
// PodCreationTimeout determines timeout in milliseconds for pods to be created after dispatching job.
// +kubebuilder:default=-1
PodCreationTimeout int `json:"podCreationTimeout,omitempty"`
//podCreationTimeout: //int (default blank)
// podCreationTimeout: //int (default blank)

// ControllerResources defines the cpu and memory resource requirements for the MCAD Controller
// +kubebuilder:default={}
Expand All @@ -63,8 +63,9 @@ type MCADStatus struct {
Ready bool `json:"ready"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// MCAD is the Schema for the mcads API
type MCAD struct {
Expand All @@ -75,15 +76,11 @@ type MCAD struct {
Status MCADStatus `json:"status,omitempty"`
}

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

// MCADList contains a list of MCAD
type MCADList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []MCAD `json:"items"`
}

func init() {
SchemeBuilder.Register(&MCAD{}, &MCADList{})
}
51 changes: 51 additions & 0 deletions api/codeflare/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2023.
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 v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// Kind takes an unqualified kind and returns back a Group qualified GroupKind.
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
SchemeGroupVersion = schema.GroupVersion{Group: "codeflare.codeflare.dev", Version: "v1alpha1"}
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
)

// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&MCAD{},
&MCADList{},
&InstaScale{},
&InstaScaleList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3180604

Please sign in to comment.