Skip to content

Commit

Permalink
cleanup tests and bash indentation (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored Feb 1, 2022
1 parent 0b73c71 commit afb70fa
Show file tree
Hide file tree
Showing 42 changed files with 995 additions and 910 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/shellcheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Controls when the workflow will run
on:
# Triggers the workflow on pull request events but only for the main branch
pull_request:
branches: [ master ]

name: 'Trigger: Push action'

jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: -e SC2046 -e SC1091 -e SC2086 -e SC2090 -e SC2089
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,4 @@ jobs:
# Runs a set of commands using the runners shell
- name: Deploy a MinIO Tenant with KES via Operator UI
run: |
curl -sLO "https://dl.k8s.io/release/v1.23.1/bin/linux/amd64/kubectl" -o kubectl
chmod +x kubectl
mv kubectl /usr/local/bin
curl -sLO "https://dl.min.io/client/mc/release/linux-amd64/mc" -o mc
chmod +x mc
mv mc /usr/local/bin
"${GITHUB_WORKSPACE}/testing/console-tenant+kes.sh"
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,4 @@ jobs:
# Runs a set of commands using the runners shell
- name: Logs test on Kind
run: |
curl -sLO "https://dl.k8s.io/release/v1.23.1/bin/linux/amd64/kubectl" -o kubectl
chmod +x kubectl
mv kubectl /usr/local/bin
"${GITHUB_WORKSPACE}/testing/check-logs.sh"
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,4 @@ jobs:
# Runs a set of commands using the runners shell
- name: Prometheus test on Kind
run: |
curl -sLO "https://dl.k8s.io/release/v1.23.1/bin/linux/amd64/kubectl" -o kubectl
chmod +x kubectl
mv kubectl /usr/local/bin
"${GITHUB_WORKSPACE}/testing/check-prometheus.sh"
3 changes: 0 additions & 3 deletions .github/workflows/bash.yml → .github/workflows/tenant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,4 @@ jobs:
# Runs a set of commands using the runners shell
- name: Deploy a MinIO Tenant on Kind
run: |
curl -sLO "https://dl.k8s.io/release/v1.23.1/bin/linux/amd64/kubectl" -o kubectl
chmod +x kubectl
mv kubectl /usr/local/bin
"${GITHUB_WORKSPACE}/testing/deploy-tenant.sh"
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ linters:
- deadcode
- structcheck
- gomodguard
- gofmt
- unused
- structcheck
- unconvert
- varcheck
- gofumpt

issues:
exclude-use-default: false
Expand All @@ -37,4 +37,4 @@ issues:
- deadcode

service:
golangci-lint-version: 1.42.0 # use the fixed version to not introduce new linters unexpectedly
golangci-lint-version: 1.43.0 # use the fixed version to not introduce new linters unexpectedly
1,442 changes: 766 additions & 676 deletions CREDITS

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ all: build logsearchapi
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.42.0)
@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.43.0)

verify: getdeps govet gotest lint

Expand Down
6 changes: 3 additions & 3 deletions examples/kustomization/base/tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ spec:
image: "" # defaults to quay.io/prometheus/prometheus:latest
sidecarimage: "" # defaults to alpine
initimage: "" # defaults to busybox:1.33.1
diskCapacityGB: 10
diskCapacityGB: 1
storageClassName: standard
annotations: { }
labels: { }
Expand Down Expand Up @@ -203,7 +203,7 @@ spec:
annotations: { }
labels: { }
audit:
diskCapacityGB: 10
diskCapacityGB: 1
## Postgres setup for LogSearch API
db:
image: "" # defaults to library/postgres
Expand All @@ -216,7 +216,7 @@ spec:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storage: 1Gi
resources: { }
nodeSelector: { }
affinity:
Expand Down
2 changes: 1 addition & 1 deletion examples/kustomization/tenant-lite/tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ spec:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storage: 2Gi
2 changes: 1 addition & 1 deletion examples/kustomization/tenant-tiny/tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ spec:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storage: 2Gi
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ require (
github.com/prometheus-operator/prometheus-operator/pkg/client v0.46.0
github.com/stretchr/testify v1.7.0
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.20.2
k8s.io/apiextensions-apiserver v0.20.2
k8s.io/apimachinery v0.20.2
k8s.io/client-go v0.20.2
k8s.io/code-generator v0.20.2
k8s.io/klog/v2 v2.4.0
sigs.k8s.io/controller-runtime v0.8.0
sigs.k8s.io/yaml v1.2.0
)

require (
Expand Down Expand Up @@ -106,10 +106,10 @@ require (
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.57.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/gengo v0.0.0-20201113003025-83324d819ded // indirect
k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd // indirect
k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.0.2 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
4 changes: 2 additions & 2 deletions k8s/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ ROOT_PKG=github.com/minio/operator

# Grab code-generator version from go.sum
CODEGEN_VERSION=$(grep 'k8s.io/code-generator' go.mod | awk '{print $2}' | sed 's/\/go.mod//g' | head -1)
CODEGEN_PKG=$(echo `go env GOPATH`"/pkg/mod/k8s.io/code-generator@${CODEGEN_VERSION}")
GOPATH=$(go env GOPATH)
CODEGEN_PKG="${GOPATH}/pkg/mod/k8s.io/code-generator@${CODEGEN_VERSION}"

if [[ ! -d ${CODEGEN_PKG} ]]; then
echo "${CODEGEN_PKG} is missing. Running 'go mod download'."
Expand All @@ -34,7 +35,6 @@ echo ">> Temporary output directory ${TEMP_DIR}"
# Ensure we can execute.
chmod +x ${CODEGEN_PKG}/generate-groups.sh


# generate the code with:
# --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
Expand Down
1 change: 0 additions & 1 deletion kubectl-minio/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ func (o *operatorInitCmd) run(writer io.Writer) error {
}

if o.operatorOpts.ConsoleImage != "" {

kustomizationYaml.PatchesJson6902 = append(kustomizationYaml.PatchesJson6902, types.Patch{
Patch: o.serializeJSONPachOps([]interface{}{
opStr{
Expand Down
15 changes: 8 additions & 7 deletions kubectl-minio/cmd/kubectl-minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ const (
kubeconfig = "kubeconfig"
)

var confPath string
var rootCmd = &cobra.Command{
Use: "minio",
Long: minioDesc,
SilenceUsage: true,
}
var (
confPath string
rootCmd = &cobra.Command{
Use: "minio",
Long: minioDesc,
SilenceUsage: true,
}
)

func init() {
rootCmd.PersistentFlags().StringVar(&confPath, kubeconfig, "", "Custom kubeconfig path")

log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)

}

// New creates a new root command for kubectl-minio
Expand Down
6 changes: 2 additions & 4 deletions kubectl-minio/cmd/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func newProxyCmd(out io.Writer, errOut io.Writer) *cobra.Command {

// run initializes local config and installs MinIO Operator to Kubernetes cluster.
func (o *operatorProxyCmd) run() error {

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -158,8 +157,8 @@ func servicePortForwardPort(ctx context.Context, namespace, service, port string
log.Printf("failed to capture stdout or stderr\n")
return
}
//outStr, errStr := string(stdout), string(stderr)
//fmt.Printf("\nout:\n%s\nerr:\n%s\n", outStr, errStr)
// outStr, errStr := string(stdout), string(stderr)
// fmt.Printf("\nout:\n%s\nerr:\n%s\n", outStr, errStr)
}()
return ch
}
Expand All @@ -176,7 +175,6 @@ func copyAndCapture(r io.Reader, dcolor color.Attribute) error {
theColor := color.New(dcolor)
//_, err := w.Write(d)
_, err := theColor.Print(string(d))

if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion kubectl-minio/cmd/resources/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func Pool(opts *TenantOptions, volumes int32, q resource.Quantity) miniov2.Pool

// GetSchemeDecoder returns a decoder for the scheme's that we use
func GetSchemeDecoder() func(data []byte, defaults *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) {

sch := runtime.NewScheme()
scheme.AddToScheme(sch)
apiextensionv1.AddToScheme(sch)
Expand Down
2 changes: 1 addition & 1 deletion logsearchapi/server/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func searchQueryFromRequest(r *http.Request) (*SearchQuery, error) {
timeEnd = &ts
}

var pageSize = 10
pageSize := 10
if psParam := values.Get("pageSize"); psParam != "" {
pageSize, err = strconv.Atoi(psParam)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/minio.min.io/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func ExtractTar(filesToExtract []string, basePath, tarFileName string) error {
tr = tar.NewReader(gz)
}

var success = len(filesToExtract)
success := len(filesToExtract)
for {
header, err := tr.Next()
if errors.Is(err, io.EOF) {
Expand All @@ -200,7 +200,7 @@ func ExtractTar(filesToExtract []string, basePath, tarFileName string) error {
}
if header.Typeflag == tar.TypeReg {
if name := find(filesToExtract, header.Name); name != "" {
outFile, err := os.OpenFile(basePath+path.Base(name), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
outFile, err := os.OpenFile(basePath+path.Base(name), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o777)
if err != nil {
return fmt.Errorf("Tar file extraction failed while opening file: %s, at index: %d, with: %w", name, success, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/minio.min.io/v2/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func ExtractTar(filesToExtract []string, basePath, tarFileName string) error {
tr = tar.NewReader(gz)
}

var success = len(filesToExtract)
success := len(filesToExtract)
for {
header, err := tr.Next()
if errors.Is(err, io.EOF) {
Expand All @@ -264,7 +264,7 @@ func ExtractTar(filesToExtract []string, basePath, tarFileName string) error {
}
if header.Typeflag == tar.TypeReg {
if name := find(filesToExtract, header.Name); name != "" {
outFile, err := os.OpenFile(basePath+path.Base(name), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
outFile, err := os.OpenFile(basePath+path.Base(name), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o777)
if err != nil {
return fmt.Errorf("Tar file extraction failed while opening file: %s, at index: %d, with: %w", name, success, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/cluster/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (c *Controller) fetchArtifacts(tenant *miniov2.Tenant) (latest time.Time, e
}
}

f, err := os.OpenFile(basePath+"image.tar", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
f, err := os.OpenFile(basePath+"image.tar", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o777)
if err != nil {
return latest, err
}
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/cluster/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
// checkConsoleSvc validates the existence of the MinIO service and validate it's status against what the specification
// states
func (c *Controller) checkConsoleSvc(ctx context.Context, tenant *miniov2.Tenant, nsName types.NamespacedName) error {

// Handle the Internal ClusterIP Service for Tenant
svc, err := c.serviceLister.Services(tenant.Namespace).Get(tenant.ConsoleCIServiceName())
if err != nil {
Expand Down
9 changes: 3 additions & 6 deletions pkg/controller/cluster/http_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const (

// BucketSrvHandler - POST /webhook/v1/bucketsrv/{namespace}/{name}?bucket={bucket}
func (c *Controller) BucketSrvHandler(w http.ResponseWriter, r *http.Request) {

vars := mux.Vars(r)
v := r.URL.Query()

Expand Down Expand Up @@ -207,7 +206,6 @@ func (c *Controller) GetenvHandler(w http.ResponseWriter, r *http.Request) {

// CRDConversionHandler - POST /webhook/v1/crd-conversion
func (c *Controller) CRDConversionHandler(w http.ResponseWriter, r *http.Request) {

dec := json.NewDecoder(r.Body)

var req v1.ConversionReview
Expand Down Expand Up @@ -236,7 +234,7 @@ func (c *Controller) CRDConversionHandler(w http.ResponseWriter, r *http.Request
case "v1":

// cast to v1
//tenantV1 := obj.Object.(*miniov1.Tenant)
// tenantV1 := obj.Object.(*miniov1.Tenant)
tenantV1 := miniov1.Tenant{}

// convert the runtime.Object to unstructured.Unstructured
Expand All @@ -257,7 +255,7 @@ func (c *Controller) CRDConversionHandler(w http.ResponseWriter, r *http.Request
req.Response.ConvertedObjects = append(req.Response.ConvertedObjects, runtime.RawExtension{Object: &tenantV1})
case "minio.min.io/v2":
tenantV2 := miniov2.Tenant{}
//convert to v2
// convert to v2
if err := tenantV1.ConvertTo(&tenantV2); err != nil {
log.Println(err)
w.WriteHeader(500)
Expand Down Expand Up @@ -289,7 +287,7 @@ func (c *Controller) CRDConversionHandler(w http.ResponseWriter, r *http.Request

switch req.Request.DesiredAPIVersion {
case "minio.min.io/v1":
//convert to v1
// convert to v1
var tenantV1 miniov1.Tenant
if err := tenantV1.ConvertFrom(&tenantV2); err != nil {
log.Println(err)
Expand All @@ -316,5 +314,4 @@ func (c *Controller) CRDConversionHandler(w http.ResponseWriter, r *http.Request
if _, err := w.Write(rawResp); err != nil {
log.Println(err)
}

}
5 changes: 1 addition & 4 deletions pkg/controller/cluster/main-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ type Controller struct {

// NewController returns a new sample controller
func NewController(podName string, namespacesToWatch set.StringSet, kubeClientSet kubernetes.Interface, minioClientSet clientset.Interface, promClient promclientset.Interface, statefulSetInformer appsinformers.StatefulSetInformer, deploymentInformer appsinformers.DeploymentInformer, podInformer coreinformers.PodInformer, jobInformer batchinformers.JobInformer, tenantInformer informers.TenantInformer, serviceInformer coreinformers.ServiceInformer, hostsTemplate, operatorVersion string) *Controller {

// Create event broadcaster
// Add minio-controller types to the default Kubernetes Scheme so Events can be
// logged for minio-controller types.
Expand Down Expand Up @@ -340,7 +339,6 @@ func (c *Controller) Start(threadiness int, stopCh <-chan struct{}) error {
apiWillStart := make(chan interface{})

go func() {

// Request kubernetes version from Kube ApiServer
c.getKubeAPIServerVersion()

Expand Down Expand Up @@ -792,7 +790,7 @@ func (c *Controller) syncHandler(key string) error {
}

// Check if this is fresh setup not an expansion.
//addingNewPool := len(tenant.Spec.Pools) == len(tenant.Status.Pools)
// addingNewPool := len(tenant.Spec.Pools) == len(tenant.Status.Pools)
addingNewPool := false
// count the number of initialized pools, if at least 1 is not Initialized, we are still adding a new pool
for _, poolStatus := range tenant.Status.Pools {
Expand Down Expand Up @@ -1121,7 +1119,6 @@ func (c *Controller) syncHandler(key string) error {
return err
}
if pool.Servers != *ss.Spec.Replicas {

// warn the user that replica count of an existing pool can't be changed
if tenant, err = c.updateTenantStatus(ctx, tenant, fmt.Sprintf("Can't modify server count for pool %s", pool.Name), 0); err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/cluster/minio-services.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
// checkMinIOSvc validates the existence of the MinIO service and validate it's status against what the specification
// states
func (c *Controller) checkMinIOSvc(ctx context.Context, tenant *miniov2.Tenant, nsName types.NamespacedName) error {

// Handle the Internal ClusterIP Service for Tenant
svc, err := c.serviceLister.Services(tenant.Namespace).Get(tenant.MinIOCIServiceName())
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/cluster/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ func (c *Controller) createMinIOClientCSR(ctx context.Context, tenant *miniov2.T
}

func (c *Controller) deleteOldConsoleDeployment(ctx context.Context, tenant *miniov2.Tenant, consoleDeployment string) error {

err := c.kubeClientSet.AppsV1().Deployments(tenant.Namespace).Delete(ctx, consoleDeployment, metav1.DeleteOptions{})
if err != nil {
klog.V(2).Infof(err.Error())
Expand Down
Loading

0 comments on commit afb70fa

Please sign in to comment.