-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use kube-system ns uid as cluster id.
Signed-off-by: yy <[email protected]>
- Loading branch information
Showing
2 changed files
with
24 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 15 additions & 22 deletions
37
controllers/license/internal/util/clusterid/cluster_id.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,17 @@ | ||
package clusterid | ||
|
||
//import ( | ||
// "context" | ||
// "os" | ||
// | ||
// "github.com/labring/sealos/controllers/license/internal/util/database" | ||
//) | ||
// | ||
//func GetClusterID(ctx context.Context, db *database.DataBase) (string, error) { | ||
// // TODO get cluster id from database | ||
// //id, err := db.GetClusterID(ctx) | ||
// //if errors.Is(err, mongo.ErrNoDocuments) { | ||
// // // if cluster id is not set, set it | ||
// // envID := os.Getenv("CLUSTER_ID") | ||
// // if envID == "" { | ||
// // return "", errors.New("cluster id not set") | ||
// // } | ||
// // if err := db.StoreClusterID(ctx, os.Getenv("CLUSTER_ID")); err != nil { | ||
// // return db.GetClusterID(ctx) | ||
// // } | ||
// //} | ||
// return os.Getenv("CLUSTER_ID"), nil | ||
//} | ||
import ( | ||
"context" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func GetClusterID(ctx context.Context, c client.Client) (string, error) { | ||
ns := &corev1.Namespace{} | ||
err := c.Get(ctx, client.ObjectKey{Name: "kube-system"}, ns) | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(ns.UID), nil | ||
} |