-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mehedi Hasan <[email protected]>
- Loading branch information
Showing
31 changed files
with
3,225 additions
and
2 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
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,24 @@ | ||
package cmds | ||
|
||
import ( | ||
"kubedb.dev/cli/pkg/remote_replica" | ||
|
||
"github.com/spf13/cobra" | ||
cmdutil "k8s.io/kubectl/pkg/cmd/util" | ||
) | ||
|
||
func NewCmdApp(f cmdutil.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "remote-config", | ||
Short: "", | ||
Long: "", | ||
Example: "", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
}, | ||
DisableAutoGenTag: false, | ||
DisableFlagsInUseLine: false, | ||
} | ||
cmd.AddCommand(remote_replica.MysqlAPP(f)) | ||
cmd.AddCommand(remote_replica.PostgreSQlAPP(f)) | ||
return cmd | ||
} |
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,90 @@ | ||
package common | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
|
||
api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2" | ||
cs "kubedb.dev/apimachinery/client/clientset/versioned" | ||
|
||
cm "github.com/cert-manager/cert-manager/pkg/client/clientset/versioned" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/rest" | ||
cmdutil "k8s.io/kubectl/pkg/cmd/util" | ||
as "kmodules.xyz/custom-resources/client/clientset/versioned" | ||
) | ||
|
||
type PostgresOpts struct { | ||
DB *api.Postgres | ||
DBImage string | ||
Config *rest.Config | ||
Client *kubernetes.Clientset | ||
DBClient *cs.Clientset | ||
AppcatClient *as.Clientset | ||
CertManagerClient *cm.Clientset | ||
PostgresDBName string | ||
|
||
Username string | ||
Pass string | ||
|
||
ErrWriter *bytes.Buffer | ||
} | ||
|
||
func NewPostgresOpts(f cmdutil.Factory, dbName, namespace string) (*PostgresOpts, error) { | ||
config, err := f.ToRESTConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
client, err := kubernetes.NewForConfig(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
dbClient, err := cs.NewForConfig(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
appCatClient, err := as.NewForConfig(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
certmanagerClient, err := cm.NewForConfig(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
db, err := dbClient.KubedbV1alpha2().Postgreses(namespace).Get(context.TODO(), dbName, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if db.Status.Phase != api.DatabasePhaseReady { | ||
return nil, fmt.Errorf("postgres %s/%s is not ready", namespace, dbName) | ||
} | ||
|
||
dbVersion, err := dbClient.CatalogV1alpha1().PostgresVersions().Get(context.TODO(), db.Spec.Version, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
secret, err := client.CoreV1().Secrets(db.Namespace).Get(context.TODO(), db.Spec.AuthSecret.Name, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &PostgresOpts{ | ||
DB: db, | ||
DBImage: dbVersion.Spec.DB.Image, | ||
Config: config, | ||
Client: client, | ||
DBClient: dbClient, | ||
AppcatClient: appCatClient, | ||
CertManagerClient: certmanagerClient, | ||
Username: string(secret.Data[corev1.BasicAuthUsernameKey]), | ||
Pass: string(secret.Data[corev1.BasicAuthPasswordKey]), | ||
ErrWriter: &bytes.Buffer{}, | ||
}, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package remote_replica | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
cmdutil "k8s.io/kubectl/pkg/cmd/util" | ||
) | ||
|
||
func MysqlAPP(f cmdutil.Factory) *cobra.Command { | ||
var userName, password, dns, ns string | ||
var yes bool | ||
cmd := cobra.Command{ | ||
Use: "mysql", | ||
Short: "", | ||
Long: "", | ||
Example: "", | ||
Args: nil, | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Printf("hi there from pg, user %v ,pass %v, dns:%v, ns %v \n", userName, password, dns, ns) | ||
if len(args) == 0 { | ||
log.Fatal("no database name given") | ||
} | ||
}, | ||
DisableAutoGenTag: false, | ||
DisableFlagsInUseLine: false, | ||
} | ||
cmd.PersistentFlags().StringVarP(&userName, "user", "u", "", "user name for the remote replica") | ||
cmd.PersistentFlags().StringVarP(&password, "pass", "p", "", "password name for the remote replica") | ||
cmd.PersistentFlags().StringVarP(&dns, "dns", "d", "", "dns name for the remote replica") | ||
cmd.PersistentFlags().StringVarP(&ns, "namespace", "n", "", "host namespace for the remote replica") | ||
cmd.PersistentFlags().BoolVarP(&yes, "yes", "y", false, "permission for alter password for the remote replica") | ||
|
||
return &cmd | ||
} |
Oops, something went wrong.