-
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
32 changed files
with
3,684 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,45 @@ | ||
/* | ||
Copyright AppsCode Inc. and Contributors | ||
Licensed under the AppsCode Community License 1.0.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md | ||
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 cmds | ||
|
||
import ( | ||
"kubedb.dev/cli/pkg/remote_replica" | ||
|
||
"github.com/spf13/cobra" | ||
cmdutil "k8s.io/kubectl/pkg/cmd/util" | ||
) | ||
|
||
var ( | ||
desLong = "generate appbinding , secrets for remote replica" | ||
example = "kubectl dba remote-config mysql -n <ns> -u <user_name> -p$<password> -d<dns_name> <db_name>" | ||
) | ||
|
||
func NewCmdGenApb(f cmdutil.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "remote-config", | ||
Short: desLong, | ||
Long: desLong, | ||
Example: 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,104 @@ | ||
/* | ||
Copyright AppsCode Inc. and Contributors | ||
Licensed under the AppsCode Community License 1.0.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md | ||
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 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 MySQLOpts struct { | ||
DB *api.MySQL | ||
DBImage string | ||
Config *rest.Config | ||
Client *kubernetes.Clientset | ||
DBClient *cs.Clientset | ||
AppcatClient *as.Clientset | ||
CertManagerClient *cm.Clientset | ||
Username string | ||
Pass string | ||
|
||
ErrWriter *bytes.Buffer | ||
} | ||
|
||
func NewMySQLOpts(f cmdutil.Factory, dbName, namespace string) (*MySQLOpts, 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().MySQLs(namespace).Get(context.TODO(), dbName, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if db.Status.Phase != api.DatabasePhaseReady { | ||
return nil, fmt.Errorf("MySQL %s/%s is not ready", namespace, dbName) | ||
} | ||
|
||
dbVersion, err := dbClient.CatalogV1alpha1().MySQLVersions().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 &MySQLOpts{ | ||
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,106 @@ | ||
/* | ||
Copyright AppsCode Inc. and Contributors | ||
Licensed under the AppsCode Community License 1.0.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md | ||
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 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 | ||
} |
Oops, something went wrong.