Skip to content
This repository was archived by the owner on Jan 28, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ RUN apt-get update \
RUN apt-get -y install git procps wget nano zsh inotify-tools jq
RUN wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true

# Install golangci-linter
RUN curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.21.0

ENV PATH="/usr/local/kubebuilder/bin:${PATH}"

ENV GO111MODULE=on
Expand Down
44 changes: 44 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
run:
deadline: 5m
skip-files: []

linters-settings:
linters-settings.govet:
check-shadowing: true

linters-settings.gocyclo:
min-complexity: 12.0

linters-settings.maligned:
suggest-new: true

linters-settings.goconst:
min-len: 3.0
min-occurrences: 3.0

linters-settings.misspell:
locale: "US"
ignore-words:
- listend
- analyses
- cancelling

linters:
enable:
- vet
- golint
- gofmt
- deadcode
- varcheck
- structcheck
- misspell
- errcheck
- gosimple
- govet
- ineffassign

issues:
exclude-use-default: false
max-per-linter: 0
max-same-issues: 0
exclude: []
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CRD_OPTIONS ?= "crd:trivialVersions=true"
all: manager

# Run tests
test: generate fmt vet manifests
test: generate fmt lint vet manifests
rm -rf cover.* cover
mkdir -p cover

Expand All @@ -20,7 +20,7 @@ test: generate fmt vet manifests
rm -f cover.out cover.out.tmp cover.json

# Run tests with existing cluster
test-existing: generate fmt vet manifests
test-existing: generate fmt lint vet manifests
rm -rf cover.* cover
mkdir -p cover

Expand All @@ -33,11 +33,11 @@ test-existing: generate fmt vet manifests
rm -f cover.out cover.out.tmp cover.json

# Build manager binary
manager: generate fmt vet
manager: generate fmt lint vet
go build -o bin/manager main.go

# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet
run: generate fmt lint vet
go run ./main.go

# Install CRDs into a cluster
Expand Down Expand Up @@ -78,12 +78,16 @@ manifests: controller-gen

# Run go fmt against code
fmt:
go fmt ./...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the reason of changing go fmt ./... to find . -name '*.go' | grep -v vendor | xargs gofmt -s -w?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the golangci-lint checks that the code has been simplified and I reused the fmt command from other projects to apply the simplification and to ignore vendored packages (avoids linter failures on those if vendoring is ever used)

find . -name '*.go' | grep -v vendor | xargs gofmt -s -w

# Run go vet against code
vet:
go vet ./...


# Run linting
lint:
GO111MODULE=on golangci-lint run

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/...
Expand Down
11 changes: 10 additions & 1 deletion api/v1alpha1/dbfsblock_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ type DbfsBlock struct {
Status *DbfsBlockStatus `json:"status,omitempty"`
}

// IsBeingDeleted returns true if a deletion timestamp is set
func (dbfsBlock *DbfsBlock) IsBeingDeleted() bool {
return !dbfsBlock.ObjectMeta.DeletionTimestamp.IsZero()
}

// IsSubmitted returns true if the item has been submitted to DataBricks
func (dbfsBlock *DbfsBlock) IsSubmitted() bool {
if dbfsBlock.Status == nil ||
dbfsBlock.Status.FileInfo == nil ||
Expand All @@ -81,21 +83,28 @@ func (dbfsBlock *DbfsBlock) GetHash() string {
return ""
}
h := sha1.New()
h.Write(data)
_, err = h.Write(data)
if err != nil {
return ""
}
bs := h.Sum(nil)
return fmt.Sprintf("%x", bs)
}

// DbfsBlockFinalizerName is the name of the dbfs block finalizer
const DbfsBlockFinalizerName = "dbfsBlock.finalizers.databricks.microsoft.com"

// HasFinalizer returns true if the item has the specified finalizer
func (dbfsBlock *DbfsBlock) HasFinalizer(finalizerName string) bool {
return containsString(dbfsBlock.ObjectMeta.Finalizers, finalizerName)
}

// AddFinalizer adds the specified finalizer
func (dbfsBlock *DbfsBlock) AddFinalizer(finalizerName string) {
dbfsBlock.ObjectMeta.Finalizers = append(dbfsBlock.ObjectMeta.Finalizers, finalizerName)
}

// RemoveFinalizer removes the specified finalizer
func (dbfsBlock *DbfsBlock) RemoveFinalizer(finalizerName string) {
dbfsBlock.ObjectMeta.Finalizers = removeString(dbfsBlock.ObjectMeta.Finalizers, finalizerName)
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/dbfsblock_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe("DbfsBlock", func() {
// Add any teardown steps that needs to be executed after each test
})

// Add Tests for OpenAPI validation (or additonal CRD features) specified in
// Add Tests for OpenAPI validation (or additional CRD features) specified in
// your API definition.
// Avoid adding tests for vanilla CRUD operations because they would
// test Kubernetes API server, which isn't the goal here.
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/dcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// DclusterStatus represents the status for a Dcluster
type DclusterStatus struct {
ClusterInfo *DclusterInfo `json:"cluster_info,omitempty"`
}
Expand All @@ -40,10 +41,12 @@ type Dcluster struct {
Status *DclusterStatus `json:"status,omitempty"`
}

// IsBeingDeleted returns true if a deletion timestamp is set
func (dcluster *Dcluster) IsBeingDeleted() bool {
return !dcluster.ObjectMeta.DeletionTimestamp.IsZero()
}

// IsSubmitted returns true if the item has been submitted to DataBricks
func (dcluster *Dcluster) IsSubmitted() bool {
if dcluster.Status == nil ||
dcluster.Status.ClusterInfo == nil ||
Expand All @@ -53,16 +56,20 @@ func (dcluster *Dcluster) IsSubmitted() bool {
return true
}

// DclusterFinalizerName is the name of the finalizer for the Dcluster operator
const DclusterFinalizerName = "dcluster.finalizers.databricks.microsoft.com"

// HasFinalizer returns true if the item has the specified finalizer
func (dcluster *Dcluster) HasFinalizer(finalizerName string) bool {
return containsString(dcluster.ObjectMeta.Finalizers, finalizerName)
}

// AddFinalizer adds the specified finalizer
func (dcluster *Dcluster) AddFinalizer(finalizerName string) {
dcluster.ObjectMeta.Finalizers = append(dcluster.ObjectMeta.Finalizers, finalizerName)
}

// RemoveFinalizer removes the specified finalizer
func (dcluster *Dcluster) RemoveFinalizer(finalizerName string) {
dcluster.ObjectMeta.Finalizers = removeString(dcluster.ObjectMeta.Finalizers, finalizerName)
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/dcluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe("Dcluster", func() {
// Add any teardown steps that needs to be executed after each test
})

// Add Tests for OpenAPI validation (or additonal CRD features) specified in
// Add Tests for OpenAPI validation (or additional CRD features) specified in
// your API definition.
// Avoid adding tests for vanilla CRUD operations because they would
// test Kubernetes API server, which isn't the goal here.
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/djob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// DjobStatus is the status object for the Djob
type DjobStatus struct {
JobStatus *dbmodels.Job `json:"job_status,omitempty"`
Last10Runs []dbmodels.Run `json:"last_10_runs,omitempty"`
Expand All @@ -39,27 +40,33 @@ type Djob struct {
Status *DjobStatus `json:"status,omitempty"`
}

// IsBeingDeleted returns true if a deletion timestamp is set
func (djob *Djob) IsBeingDeleted() bool {
return !djob.ObjectMeta.DeletionTimestamp.IsZero()
}

// IsSubmitted returns true if the item has been submitted to DataBricks
func (djob *Djob) IsSubmitted() bool {
if djob.Status == nil || djob.Status.JobStatus == nil || djob.Status.JobStatus.JobID == 0 {
return false
}
return djob.Status.JobStatus.JobID > 0
}

// DjobFinalizerName is the name of the djob finalizer
const DjobFinalizerName = "djob.finalizers.databricks.microsoft.com"

// HasFinalizer returns true if the item has the specified finalizer
func (djob *Djob) HasFinalizer(finalizerName string) bool {
return containsString(djob.ObjectMeta.Finalizers, finalizerName)
}

// AddFinalizer adds the specified finalizer
func (djob *Djob) AddFinalizer(finalizerName string) {
djob.ObjectMeta.Finalizers = append(djob.ObjectMeta.Finalizers, finalizerName)
}

// RemoveFinalizer removes the specified finalizer
func (djob *Djob) RemoveFinalizer(finalizerName string) {
djob.ObjectMeta.Finalizers = removeString(djob.ObjectMeta.Finalizers, finalizerName)
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/djob_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe("Djob", func() {
// Add any teardown steps that needs to be executed after each test
})

// Add Tests for OpenAPI validation (or additonal CRD features) specified in
// Add Tests for OpenAPI validation (or additional CRD features) specified in
// your API definition.
// Avoid adding tests for vanilla CRUD operations because they would
// test Kubernetes API server, which isn't the goal here.
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// package v1alpha1 contains API Schema definitions for the databricks v1 API group
// Package v1alpha1 contains API Schema definitions for the databricks v1 API group
// +kubebuilder:object:generate=true
// +groupName=databricks.microsoft.com
package v1alpha1
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func randomStringWithCharset(length int, charset string) string {
return string(b)
}

// RandomString generates a random string from a subset of characters
func RandomString(length int) string {
return randomStringWithCharset(length, charset)
}
6 changes: 1 addition & 5 deletions api/v1alpha1/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ limitations under the License.
package v1alpha1

import (
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Helpers", func() {

const timeout = time.Second * 5

BeforeEach(func() {
// Add any setup steps that needs to be executed before each test
})
Expand All @@ -35,7 +31,7 @@ var _ = Describe("Helpers", func() {
// Add any teardown steps that needs to be executed after each test
})

// Add Tests for OpenAPI validation (or additonal CRD features) specified in
// Add Tests for OpenAPI validation (or additional CRD features) specified in
// your API definition.
// Avoid adding tests for vanilla CRUD operations because they would
// test Kubernetes API server, which isn't the goal here.
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/run_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,33 @@ type Run struct {
Status *dbazure.JobsRunsGetOutputResponse `json:"status,omitempty"`
}

// IsBeingDeleted returns true if a deletion timestamp is set
func (run *Run) IsBeingDeleted() bool {
return !run.ObjectMeta.DeletionTimestamp.IsZero()
}

// IsSubmitted returns true if the item has been submitted to DataBricks
func (run *Run) IsSubmitted() bool {
if run.Status == nil || run.Status.Metadata.JobID == 0 {
return false
}
return run.Status.Metadata.JobID > 0
}

// RunFinalizerName is the name of the run finalizer
const RunFinalizerName = "run.finalizers.databricks.microsoft.com"

// HasFinalizer returns true if the item has the specified finalizer
func (run *Run) HasFinalizer(finalizerName string) bool {
return containsString(run.ObjectMeta.Finalizers, finalizerName)
}

// AddFinalizer adds the specified finalizer
func (run *Run) AddFinalizer(finalizerName string) {
run.ObjectMeta.Finalizers = append(run.ObjectMeta.Finalizers, finalizerName)
}

// RemoveFinalizer removes the specified finalizer
func (run *Run) RemoveFinalizer(finalizerName string) {
run.ObjectMeta.Finalizers = removeString(run.ObjectMeta.Finalizers, finalizerName)
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/run_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var _ = Describe("Run", func() {
// Add any teardown steps that needs to be executed after each test
})

// Add Tests for OpenAPI validation (or additonal CRD features) specified in
// Add Tests for OpenAPI validation (or additional CRD features) specified in
// your API definition.
// Avoid adding tests for vanilla CRUD operations because they would
// test Kubernetes API server, which isn't the goal here.
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/secretscope_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,30 @@ type SecretScope struct {
Status SecretScopeStatus `json:"status,omitempty"`
}

// IsSubmitted returns true if the item has been submitted to DataBricks
func (ss *SecretScope) IsSubmitted() bool {
return ss.Status.SecretScope != nil
}

// IsBeingDeleted returns true if a deletion timestamp is set
func (ss *SecretScope) IsBeingDeleted() bool {
return !ss.ObjectMeta.DeletionTimestamp.IsZero()
}

// SecretScopeFinalizerName is the name of the secretscope finalizer
const SecretScopeFinalizerName = "secretscope.finalizers.databricks.microsoft.com"

// HasFinalizer returns true if the item has the specified finalizer
func (ss *SecretScope) HasFinalizer(finalizerName string) bool {
return containsString(ss.ObjectMeta.Finalizers, finalizerName)
}

// AddFinalizer adds the specified finalizer
func (ss *SecretScope) AddFinalizer(finalizerName string) {
ss.ObjectMeta.Finalizers = append(ss.ObjectMeta.Finalizers, finalizerName)
}

// RemoveFinalizer removes the specified finalizer
func (ss *SecretScope) RemoveFinalizer(finalizerName string) {
ss.ObjectMeta.Finalizers = removeString(ss.ObjectMeta.Finalizers, finalizerName)
}
Expand Down
Loading