Skip to content

Commit

Permalink
Update go code to operator-sdk 1.3.0
Browse files Browse the repository at this point in the history
- Update pkg, api, and controller go code
- Update related Makefile rules and .gitignore

Signed-off-by: Mamduh Alassi <mamduhala@mellanox.com>
  • Loading branch information
Mmduh-483 committed Jan 24, 2021
1 parent f12f5b6 commit f890485
Show file tree
Hide file tree
Showing 36 changed files with 676 additions and 966 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin
testbin/*

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
build/_output/

# Kubernetes Generated files - skip generated files, except for vendored files

!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- "1.13"
- "1.15"

env:
- IMAGE_NAME=mellanox/network-operator
Expand Down
27 changes: 24 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 NVIDIA
# Copyright 2021 NVIDIA
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,11 +74,11 @@ $(GOBIN):
$(BUILDDIR): | $(BASE) ; $(info Creating build directory...)
@cd $(BASE) && mkdir -p $@

build: $(BUILDDIR)/$(BINARY_NAME) ; $(info Building $(BINARY_NAME)...) @ ## Build executable file
build: generate $(BUILDDIR)/$(BINARY_NAME) ; $(info Building $(BINARY_NAME)...) @ ## Build executable file
$(info Done!)

$(BUILDDIR)/$(BINARY_NAME): $(GOFILES) | $(BUILDDIR)
@cd $(BASE)/cmd/manager && CGO_ENABLED=0 $(GO) build -o $(BUILDDIR)/$(BINARY_NAME) -tags no_openssl -v -ldflags=$(LDFLAGS)
@cd $(BASE) && CGO_ENABLED=0 $(GO) build -o $(BUILDDIR)/$(BINARY_NAME) -tags no_openssl -v -ldflags=$(LDFLAGS)

# Tools

Expand Down Expand Up @@ -140,3 +140,24 @@ clean: ; $(info Cleaning...) @ ## Cleanup everything
help: ## Show this message
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

generate: controller-gen ## Generate code
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 NVIDIA
Copyright 2021 NVIDIA
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,10 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// NOTE: Boilerplate only. Ignore this file.

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

Expand All @@ -27,9 +25,12 @@ import (
)

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

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

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 NVIDIA
Copyright 2021 NVIDIA
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -20,9 +20,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

const (
MacvlanNetworkCRDName = "MacvlanNetwork"
)
Expand Down Expand Up @@ -54,11 +51,12 @@ type MacvlanNetworkStatus struct {
Reason string `json:"reason,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// kubebuilder:object:generate
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster

// MacvlanNetwork is the Schema for the macvlannetworks API
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=macvlannetworks,scope=Cluster
type MacvlanNetwork struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -67,7 +65,8 @@ type MacvlanNetwork struct {
Status MacvlanNetworkStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// kubebuilder:object:generate

// MacvlanNetworkList contains a list of MacvlanNetwork
type MacvlanNetworkList struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 NVIDIA
Copyright 2021 NVIDIA
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -20,9 +20,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

const (
NicClusterPolicyCRDName = "NicClusterPolicy"
)
Expand Down Expand Up @@ -93,8 +90,7 @@ type SecondaryNetworkSpec struct {
// NicClusterPolicySpec defines the desired state of NicClusterPolicy
type NicClusterPolicySpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
// Add custom validation using kubebuilder tags: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html
// Important: Run "make" to regenerate code after modifying this file

OFEDDriver *OFEDDriverSpec `json:"ofedDriver,omitempty"`
NVPeerDriver *NVPeerDriverSpec `json:"nvPeerDriver,omitempty"`
Expand All @@ -112,8 +108,7 @@ type AppliedState struct {
// NicClusterPolicyStatus defines the observed state of NicClusterPolicy
type NicClusterPolicyStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
// Add custom validation using kubebuilder tags: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html
// Important: Run "make" to regenerate code after modifying this file

// Reflects the current state of the cluster policy
// +kubebuilder:validation:Enum={"ignore", "notReady", "ready", "error"}
Expand All @@ -124,11 +119,12 @@ type NicClusterPolicyStatus struct {
AppliedStates []AppliedState `json:"appliedStates,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// kubebuilder:object:generate
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster

// NicClusterPolicy is the Schema for the nicclusterpolicies API
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=nicclusterpolicies,scope=Cluster
type NicClusterPolicy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -137,7 +133,8 @@ type NicClusterPolicy struct {
Status NicClusterPolicyStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// kubebuilder:object:generate

// NicClusterPolicyList contains a list of NicClusterPolicy
type NicClusterPolicyList struct {
Expand Down

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

Loading

0 comments on commit f890485

Please sign in to comment.