-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from wuxs/feat/clean-invalid-enabled-tenants-…
…in-plugin feat: add fix subcommand to clean invalid enabled tenants in plugin
- Loading branch information
Showing
6 changed files
with
233 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package plugin | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/tkeel-io/cli/pkg/kubernetes" | ||
"github.com/tkeel-io/cli/pkg/print" | ||
) | ||
|
||
var FixCmd = &cobra.Command{ | ||
Use: "fix", | ||
Short: "Clean up invalid enabled tenants in the plugin", | ||
Example: ` | ||
# Clean up all plugins | ||
tkeel plugin fix | ||
# Clean up the specified plugins | ||
tkeel plugin fix [plugin-id ...] | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
plugins := args | ||
print.PendingStatusEvent(os.Stdout, "Clean invalid enabled tenants....") | ||
daprStatus, err := kubernetes.CheckDapr() | ||
if err != nil { | ||
print.FailureStatusEvent(os.Stdout, err.Error()) | ||
os.Exit(1) | ||
} | ||
tenantList, err := kubernetes.TenantList() | ||
if err != nil { | ||
print.FailureStatusEvent(os.Stdout, err.Error()) | ||
os.Exit(1) | ||
} | ||
var tenants = make([]string, len(tenantList)) | ||
for _, tenant := range tenantList { | ||
tenants = append(tenants, tenant.ID) | ||
} | ||
|
||
if len(plugins) == 0 { | ||
pluginList, err := kubernetes.InstalledPlugin() | ||
if err != nil { | ||
print.FailureStatusEvent(os.Stdout, err.Error()) | ||
os.Exit(1) | ||
} | ||
plugins = make([]string, len(pluginList)) | ||
for i, plugin := range pluginList { | ||
plugins[i] = plugin.Name | ||
} | ||
} | ||
|
||
for _, plugin := range plugins { | ||
err := kubernetes.CleanInvalidTenants(plugin, tenants, daprStatus.Namespace) | ||
if err != nil { | ||
print.FailureStatusEvent(os.Stdout, fmt.Sprintf("clean invalid tenants failed, plugin: %s, err: %s", plugin, err.Error())) | ||
} | ||
} | ||
print.InfoStatusEvent(os.Stdout, "Invalid tenant cleanup completed") | ||
}, | ||
} | ||
|
||
func init() { | ||
FixCmd.Flags().BoolP("help", "h", false, "Print this help message") | ||
PluginCmd.AddCommand(FixCmd) | ||
} |
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,16 @@ | ||
package redis | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/go-redis/redis/v8" | ||
) | ||
|
||
func NewClient(host string, port int, password string, db int) *redis.Client { | ||
rdb := redis.NewClient(&redis.Options{ | ||
Addr: fmt.Sprintf("%s:%d", host, port), | ||
Password: password, // no password set | ||
DB: db, // use default DB | ||
}) | ||
return rdb | ||
} |
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
Oops, something went wrong.