Skip to content

Commit

Permalink
cleanup plugin build, simplify build (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed Aug 24, 2020
1 parent 4500c94 commit 4612151
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 1,803 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ minio-operator
.idea/
dist/
kubectl-minio/kubectl-minio
*.test*.minisig
*.minisig
kubectl-minio/crds
16 changes: 16 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ builds:
- -trimpath
hooks:
post: ./minisign.sh {{ .Path }}
-
id: kubectl-minio
dir: kubectl-minio
binary: kubectl-minio
goos:
- linux
goarch:
- amd64
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X main.Version={{.Tag}}
flags:
- -trimpath
hooks:
post: ./minisign.sh {{ .Path }}

archives:
-
Expand Down
30 changes: 16 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ GOPATH := $(shell go env GOPATH)
GOARCH := $(shell go env GOARCH)
GOOS := $(shell go env GOOS)

CRD_GEN_PATH=operator-kustomize/crds/
OPERATOR_YAML=./operator-kustomize/
TENANT_CRD=$(OPERATOR_YAML)crds/minio.min.io_tenants.yaml
PLUGIN_HOME=./kubectl-minio
PLUGIN_OPERATOR_YAML=$(PLUGIN_HOME)/static
PLUGIN_CRD_COPY=$(PLUGIN_OPERATOR_YAML)/crd.yaml
KUSTOMIZE_HOME=operator-kustomize
KUSTOMIZE_CRDS=$(KUSTOMIZE_HOME)/crds/

PLUGIN_HOME=kubectl-minio

all: build

getdeps:
@echo "Checking dependencies"
@mkdir -p ${GOPATH}/bin
@which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.27.0)
@which controller-gen 1>/dev/null || (echo "Installing controller-gen" && GO111MODULE=off go get sigs.k8s.io/controller-tools/cmd/controller-gen)
@which statik 1>/dev/null || (echo "Installing statik" && GO111MODULE=off go get github.com/rakyll/statik)

verify: govet gotest lint
verify: getdeps govet gotest lint

build: verify
build: regen-crd verify plugin
@CGO_ENABLED=0 GOOS=linux go build -trimpath --ldflags $(LDFLAGS) -o minio-operator
@docker build -t $(TAG) .

Expand All @@ -45,12 +47,12 @@ clean:
@find . -name '*~' | xargs rm -fv

regen-crd:
@controller-gen crd:trivialVersions=true paths="./..." output:crd:artifacts:config=$(CRD_GEN_PATH)
@controller-gen crd:trivialVersions=true paths="./..." output:crd:artifacts:config=$(KUSTOMIZE_CRDS)

statik:
@echo "Building static assets"
@statik -src=$(KUSTOMIZE_HOME) -dest $(PLUGIN_HOME) -f

plugin: regen-crd
@rm -rf $(PLUGIN_OPERATOR_YAML)
@mkdir -p $(PLUGIN_OPERATOR_YAML)
@cp $(TENANT_CRD) $(PLUGIN_CRD_COPY)
@cp $(OPERATOR_YAML)/*.yaml $(PLUGIN_OPERATOR_YAML)
@cd $(PLUGIN_HOME); go build -o kubectl-minio main.go
@echo "Building 'kubectl-minio' binary"
@(cd $(PLUGIN_HOME); go build -o kubectl-minio main.go)
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
github.com/shirou/gopsutil v2.20.6+incompatible // indirect
github.com/stretchr/testify v1.4.0
k8s.io/api v0.18.6
k8s.io/apiextensions-apiserver v0.18.6 // indirect
k8s.io/apimachinery v0.18.6
k8s.io/client-go v0.18.6
k8s.io/klog/v2 v2.3.0
Expand Down
125 changes: 0 additions & 125 deletions go.sum

Large diffs are not rendered by default.

30 changes: 17 additions & 13 deletions kubectl-minio/cmd/kubectl-minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package cmd

import (
"io/ioutil"
"log"

"github.com/rakyll/statik/fs"
Expand Down Expand Up @@ -49,7 +48,8 @@ kubectl plugin to manage MinIO operator CRDs.`
)

func init() {
fs, err := fs.New()
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
emfs, err := fs.New()
if err != nil {
log.Fatal(err)
}
Expand All @@ -59,33 +59,37 @@ func init() {
rbacv1.AddToScheme(sch)
decode := serializer.NewCodecFactory(sch).UniversalDeserializer().Decode

crd, err := fs.Open("/crd.yaml")
if err != nil {
log.Fatal(err)
}
contents, err := ioutil.ReadAll(crd)
contents, err := fs.ReadFile(emfs, "/crds/minio.min.io_tenants.yaml")
if err != nil {
log.Fatal(err)
}

obj, _, err := decode(contents, nil, nil)
if err != nil {
log.Fatal(err)
}
crdObj = obj.(*apiextensionv1.CustomResourceDefinition)

cr, err := fs.Open("/cluster-role.yaml")
if err != nil {
log.Fatal(err)
var ok bool
crdObj, ok = obj.(*apiextensionv1.CustomResourceDefinition)
if !ok {
log.Fatal("Unable to locate CustomResourceDefinition object")
}
contents, err = ioutil.ReadAll(cr)

contents, err = fs.ReadFile(emfs, "/cluster-role.yaml")
if err != nil {
log.Fatal(err)
}

obj, _, err = decode(contents, nil, nil)
if err != nil {
log.Fatal(err)
}
crObj = obj.(*rbacv1.ClusterRole)

crObj, ok = obj.(*rbacv1.ClusterRole)
if !ok {
log.Fatal("Unable to locate ClusterRole object")
}

}

// NewCmdMinIO creates a new root command for kubectl-minio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -127,7 +127,7 @@ func (o *operatorCreateCmd) run() error {
func createCRD(client *apiextension.Clientset, crd *apiextensionv1.CustomResourceDefinition) error {
_, err := client.ApiextensionsV1beta1().CustomResourceDefinitions().Create(context.Background(), crd, v1.CreateOptions{})
if err != nil {
if kerrors.IsAlreadyExists(err) {
if k8serrors.IsAlreadyExists(err) {
return fmt.Errorf("CustomResourceDefinition %s: already present, skipped", crd.ObjectMeta.Name)
}
return err
Expand All @@ -139,7 +139,7 @@ func createCRD(client *apiextension.Clientset, crd *apiextensionv1.CustomResourc
func createCR(client *kubernetes.Clientset, cr *rbacv1.ClusterRole) error {
_, err := client.RbacV1().ClusterRoles().Create(context.Background(), cr, v1.CreateOptions{})
if err != nil {
if kerrors.IsAlreadyExists(err) {
if k8serrors.IsAlreadyExists(err) {
return fmt.Errorf("ClusterRole %s: already present, skipped", cr.ObjectMeta.Name)
}
return err
Expand All @@ -151,7 +151,7 @@ func createCR(client *kubernetes.Clientset, cr *rbacv1.ClusterRole) error {
func createSA(client *kubernetes.Clientset, sa *corev1.ServiceAccount) error {
_, err := client.CoreV1().ServiceAccounts(sa.ObjectMeta.Namespace).Create(context.Background(), sa, v1.CreateOptions{})
if err != nil {
if kerrors.IsAlreadyExists(err) {
if k8serrors.IsAlreadyExists(err) {
return fmt.Errorf("ServiceAccount %s: already present, skipped", sa.ObjectMeta.Name)
}
return err
Expand All @@ -163,7 +163,7 @@ func createSA(client *kubernetes.Clientset, sa *corev1.ServiceAccount) error {
func createClusterRB(client *kubernetes.Clientset, crb *rbacv1.ClusterRoleBinding) error {
_, err := client.RbacV1().ClusterRoleBindings().Create(context.Background(), crb, v1.CreateOptions{})
if err != nil {
if kerrors.IsAlreadyExists(err) {
if k8serrors.IsAlreadyExists(err) {
return fmt.Errorf("ClusterRoleBinding %s: already present, skipped", crb.ObjectMeta.Name)
}
return err
Expand All @@ -175,7 +175,7 @@ func createClusterRB(client *kubernetes.Clientset, crb *rbacv1.ClusterRoleBindin
func createDeployment(client *kubernetes.Clientset, d *appsv1.Deployment) error {
_, err := client.AppsV1().Deployments(d.ObjectMeta.Namespace).Create(context.Background(), d, v1.CreateOptions{})
if err != nil {
if kerrors.IsAlreadyExists(err) {
if k8serrors.IsAlreadyExists(err) {
return fmt.Errorf("MinIO Operator Deployment %s: already present, skipped", d.ObjectMeta.Name)
}
return err
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"github.com/minio/kubectl-minio/cmd/helpers"
"github.com/spf13/cobra"
kerrors "k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -46,7 +46,7 @@ func newTenantCmd(out io.Writer, errOut io.Writer) *cobra.Command {
}
_, err = client.ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.Background(), crdObj.GetObjectMeta().GetName(), v1.GetOptions{})
if err != nil {
if kerrors.IsNotFound(err) {
if k8serrors.IsNotFound(err) {
return fmt.Errorf("CustomResourceDefinition %s: not found, please run 'kubectl minio operator create' before using tenant command", crdObj.ObjectMeta.Name)
}
return err
Expand Down
76 changes: 0 additions & 76 deletions kubectl-minio/static/cluster-role.yaml

This file was deleted.

0 comments on commit 4612151

Please sign in to comment.