-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cluster id for license controller. (#4237)
* add cluster id for license controller. Signed-off-by: yy <[email protected]> * fix typo error. Signed-off-by: yy <[email protected]> * add cluster id and db for it. Signed-off-by: yy <[email protected]> * use kube-system ns uid as cluster id. Signed-off-by: yy <[email protected]> * delete cluster id env Signed-off-by: yy <[email protected]> * fix license check func. Signed-off-by: yy <[email protected]> * chore: use id first 8 char as is Signed-off-by: yy <[email protected]> * ci: fix make license. Signed-off-by: yy <[email protected]> * ci: fix typos. Signed-off-by: yy <[email protected]> --------- Signed-off-by: yy <[email protected]>
- Loading branch information
Showing
11 changed files
with
148 additions
and
24 deletions.
There are no files selected for viewing
File renamed without changes.
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
41 changes: 41 additions & 0 deletions
41
controllers/license/internal/controller/license_activator.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright © 2023 sealos. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package controller | ||
|
||
import ( | ||
"context" | ||
|
||
licensev1 "github.com/labring/sealos/controllers/license/api/v1" | ||
accountutil "github.com/labring/sealos/controllers/license/internal/util/account" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type LicenseActivator struct { | ||
client.Client | ||
} | ||
|
||
func (a *LicenseActivator) Active(ctx context.Context, license *licensev1.License) error { | ||
// TODO mv to active function | ||
switch license.Spec.Type { | ||
case licensev1.AccountLicenseType: | ||
if err := accountutil.Recharge(ctx, a.Client, license); err != nil { | ||
return err | ||
} | ||
case licensev1.ClusterLicenseType: | ||
// TODO implement cluster license | ||
} | ||
return nil | ||
} |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright © 2023 sealos. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package clusterid | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
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 | ||
} | ||
res := string(ns.UID) | ||
if res == "" || len(res) < 8 { | ||
return "", fmt.Errorf("failed to get cluster id") | ||
} | ||
return res[0:8], nil | ||
} |
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
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
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
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