Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add go workspace and move containsString to pkg/util #300

Merged
merged 1 commit into from
Aug 29, 2022
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
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
}