Skip to content

Commit

Permalink
feat: add go workspace and move containsString to pkg/util (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
skyoct authored Aug 29, 2022
1 parent ebbef46 commit 88bae41
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
13 changes: 2 additions & 11 deletions controllers/database/controllers/database_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
databasev1 "github.com/labring/laf/controllers/database/api/v1"
"github.com/labring/laf/controllers/database/dbm"
"k8s.io/apimachinery/pkg/runtime"
"laf/pkg/util"
"net/url"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -70,7 +71,7 @@ func (r *DatabaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
func (r *DatabaseReconciler) apply(ctx context.Context, database *databasev1.Database) (ctrl.Result, error) {
// add the finalizer
if database.ObjectMeta.DeletionTimestamp.IsZero() {
if !containsString(database.ObjectMeta.Finalizers, "database.laf.dev") {
if !util.ContainsString(database.ObjectMeta.Finalizers, "database.laf.dev") {
database.ObjectMeta.Finalizers = append(database.ObjectMeta.Finalizers, "database.laf.dev")
if err := r.Update(ctx, database); err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -249,13 +250,3 @@ func (r *DatabaseReconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&databasev1.Database{}).
Complete(r)
}

// TODO: move it to pkg/util
func containsString(finalizers []string, s string) bool {
for _, f := range finalizers {
if f == s {
return true
}
}
return false
}
9 changes: 9 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
go 1.18

use (
.
./controllers/application
./controllers/database
./controllers/oss
./controllers/gateway
)
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
10 changes: 10 additions & 0 deletions pkg/util/string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package util

func ContainsString(finalizers []string, s string) bool {
for _, f := range finalizers {
if f == s {
return true
}
}
return false
}

0 comments on commit 88bae41

Please sign in to comment.