Skip to content

Commit

Permalink
add support for remote-config
Browse files Browse the repository at this point in the history
Signed-off-by: Mehedi Hasan <[email protected]>
  • Loading branch information
heheh13 committed Sep 25, 2023
1 parent 2b95f75 commit 20c2b28
Show file tree
Hide file tree
Showing 34 changed files with 3,822 additions and 2 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/cert-manager/cert-manager v1.9.1
github.com/fatih/camelcase v1.0.0
github.com/go-sql-driver/mysql v1.6.0
github.com/spf13/cobra v1.7.0
Expand All @@ -21,11 +22,13 @@ require (
k8s.io/component-base v0.25.3
k8s.io/klog/v2 v2.80.1
k8s.io/kubectl v0.25.1
kmodules.xyz/cert-manager-util v0.25.0
kmodules.xyz/client-go v0.25.30
kmodules.xyz/custom-resources v0.25.2
kmodules.xyz/monitoring-agent-api v0.25.1
kubedb.dev/apimachinery v0.35.0
kubedb.dev/db-client-go v0.0.8-0.20230818101900-6ddd035705ef
sigs.k8s.io/yaml v1.3.0
stash.appscode.dev/apimachinery v0.31.0
)

Expand All @@ -42,7 +45,6 @@ require (
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cert-manager/cert-manager v1.9.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect
Expand Down Expand Up @@ -144,7 +146,6 @@ require (
sigs.k8s.io/kustomize/api v0.12.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/Masterminds/sprig/v3 => github.com/gomodules/sprig/v3 v3.2.3-0.20220405051441-0a8a99bac1b8
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,8 @@ k8s.io/utils v0.0.0-20221012122500-cfd413dd9e85 h1:cTdVh7LYu82xeClmfzGtgyspNh6Ux
k8s.io/utils v0.0.0-20221012122500-cfd413dd9e85/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk=
kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80=
kmodules.xyz/cert-manager-util v0.25.0 h1:B/1sYzdrXatzDnpB+F9IIi6DdwJs2sPBm46VPAlDtxc=
kmodules.xyz/cert-manager-util v0.25.0/go.mod h1:Zi1ZLUsrzsYs6ibdZddQCn+9VUqCuO9YqAq9QLI9RNM=
kmodules.xyz/client-go v0.25.30 h1:4qOhs1kX0oNl9tcY98PEtiUlD6TZqK9CRfqzfhZApsk=
kmodules.xyz/client-go v0.25.30/go.mod h1:r/Va2Y6t1G8X1sPRjrQC6FWB3oh/i6rjssmlfJnbCmg=
kmodules.xyz/custom-resources v0.25.2 h1:+PJgUZvbbSgyNT7EX9gUZ3PIzY2LAW03TDW8cevvXqo=
Expand Down
80 changes: 80 additions & 0 deletions mysql-bahrain-remote-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
apiVersion: v1
kind: Secret
metadata:
creationTimestamp: null
name: mysql-bahrain-remote-replica-auth
namespace: demo
stringData:
password: remote
username: remote
type: kubernetes.io/basic-auth
---
apiVersion: v1
data:
ca.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURLVENDQWhHZ0F3SUJBZ0lVTzdSU2dvcEtESUhCamYwaUI0N1JRVC9zS2U4d0RRWUpLb1pJaHZjTkFRRUwKQlFBd0pERVJNQThHQTFVRUF3d0ljRzl6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nbTZZSVRxYjEwVDV2SUdFOHB1MXNROApUNFdxQTR4VThHRFAwWkFmMS94WVRsRW1TelFrRWp3d1JnMXNMYVE1MlVtZXFWcFJ4c3hiL2lDbnBlMlFFeGFECmZ2a0h3SjNoTDdKK1ZHeGZCckZYWFdPSlJ6WWRjb3lXNkVoQkZZRUNnWUVBMEQ5VXBTd0lTWDhDcXZLZXU4aXQKR3BHQzhackNMb01Fak04eFFkVUh5T2xwMEQ3cERpM2FqWk5CVkNuVnBScEVFbDl0VUtvaEd4U3hQem1xajdYTgpid0NUdTg3MDFDQWx4K2NweC84ZnVIMTM0WDkrc0tTaEMrb0ZSOXFOVzdxSFBIRWlVQ2dzbVdPdE40TlRtYUhKCnRjN0dYNitLM0ZSYnBYZVFDQ0V2R3BFQ2dZQUI1TDUwMnRyMmtyV0YvWDdsMTlWWnJ3ZTdCalVud1k2d1NMVFYKOU43aDcyVXoxamdXMjNTNDhFZlprNjNzQks4L0l0RXBIaE1tSHRrc21KMmJ5Ym9PQzhHM1JzMmdnZUFEYlJZNwp0NmlKS2xYOERNTGgyTks1ZmxrYy9xcWJNbUUvV2Naa21zcXZyblFxR0ZjMlpSSGRIRGlac09PbmhkbHloYnhhClpUQjFnUUtCZ0VrSHk1bTZyY1pmVHJ4K3orQkFRS2dGZWllSSt3eTBhNk5MSVp2RmdMVzF2UUY5eW10RWFrUkEKc2lLR2p3T29SVVJ1YXJaWi9CbmtIK0Z4Y2MwWTUrcThhUW83eVJsWXFUOUZvVmNIb3hIbjJ1cG1iMGRjYlZOeQp3c3ljeXVTVmFGbWtDbFdlVDdhamRHQlhMaFNKNmtOSVc3U2pBUnJWZi81Wm1tUUVGdHY2Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
kind: Secret
metadata:
creationTimestamp: "2023-09-25T13:17:41Z"
labels:
controller.cert-manager.io/fao: "true"
name: mysql-bahrain-client-cert-remote
namespace: demo
resourceVersion: "875893"
uid: 38ff2cb2-14c7-4e72-bae7-82b5442089d2
type: kubernetes.io/tls
---
apiVersion: appcatalog.appscode.com/v1alpha1
kind: AppBinding
metadata:
creationTimestamp: "2023-09-25T13:34:02Z"
generation: 1
labels:
app.kubernetes.io/component: database
app.kubernetes.io/instance: mysql-bahrain
app.kubernetes.io/managed-by: kubedb.com
app.kubernetes.io/name: mysqls.kubedb.com
name: mysql-bahrain
namespace: demo
ownerReferences:
- apiVersion: kubedb.com/v1alpha2
blockOwnerDeletion: true
controller: true
kind: MySQL
name: mysql-bahrain
uid: f23cdedd-7050-4ed4-8247-63e0b8fff654
resourceVersion: "879373"
uid: 96369a74-e8e5-4b6a-a6b2-e70f8729031a
spec:
appRef:
apiGroup: kubedb.com
kind: MySQL
name: mysql-bahrain
namespace: demo
clientConfig:
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURLVENDQWhHZ0F3SUJBZ0lVTzdSU2dvcEtESUhCamYwaUI0N1JRVC9zS2U4d0RRWUpLb1pJaHZjTkFRRUwKQlFBd0pERVJNQThHQTFVRUF3d0ljRzl6ZEdkeVpYTXhEekFOQmdOVkJBb01CbXQxWW1Wa1lqQWVGdzB5TXpBNQpNVGd4TkRJNE5UQmFGdzB5TkRBNU1UY3hOREk0TlRCYU1DUXhFVEFQQmdOVkJBTU1DSEJ2YzNSbmNtVnpNUTh3CkRRWURWUVFLREFacmRXSmxaR0l3Z2dFaU1BMEdDU3FHU0liM0RRRUJBUVVBQTRJQkR3QXdnZ0VLQW9JQkFRREMKK21pRTFlUzJCaEcrZ1RnZjUzR3Z0QWg4eUNxTmppWThyd2NuVnJhNWF1MXRKallzaFdVenA4cG8wZGR0RHExQwpKTG1xTVE0YVpkYk5ScWFOZ0ZvUVBidTZpendJazF0clhuM0czdkt6ZWNKSVpTa0liNTVVTkJ6YzZqa01kU2dpClpCMTcwUndOdjQyWG4zNVR3UU9zTHdKcENYSnFEMTFMRU1IK2YrdGIvMGR4cDFvcmxuV0p4ZWZBcG50U1B4alAKWDJhaHZreCtJOUdoU3hrK0h0OWI2RGEvWjZmOXFSNkgvY1E1d05veklLbEc4czZZSFpoeFY5alM0MHN4SkhLUwpZTFlJbEIxUDMycEtjMVorVEV2Wk9nQmxVWTgzQ1RBN0FiZlRXaVprYUpmTjBWQUcyZ0lPdzhuNEpiQnptaXlUCjhFaGZtcDh1UWhCcFM2dUxTSE5KQWdNQkFBR2pVekJSTUIwR0ExVWREZ1FXQkJSVEIyUTdDQXBMdjZZOE55cHUKWXhUM0UvUkM5ekFmQmdOVkhTTUVHREFXZ0JSVEIyUTdDQXBMdjZZOE55cHVZeFQzRS9SQzl6QVBCZ05WSFJNQgpBZjhFQlRBREFRSC9NQTBHQ1NxR1NJYjNEUUVCQ3dVQUE0SUJBUUFYK0svSk80S0MwdVk5eHJGVG4rZXNyWU9HCmZ2V2k0MVBOMC9mNUY4NnZETzhLbVBMbk5vZ3I1SjZ0a2FDRVNZMGJZOVcrUnd6cnhUc2x5TXY1Rmd0bXBKT3MKdWxEbDZXeGowUTJlZ094VHZTeEJqU0pCMXBpSWVVTFJBdnJ1T2JFZm9SUExmbmgzUytwSUFzbXkzQSt2MHRldQpmTG1lbkNzdUZ2MndCSXZ1S2NleGhFT1NrZ2ZVTk1UbzU3S05ycGFYMFlzSFpNcEpzbWJkTjAwekdkRGV5SGlRCldlbjRRTWZTQW5DcTFETVQvNzZQM0NBZjhELzQvS2lsSFNhRzFtTGN6Mm5vSnZ2c1I4SDA2ZHhQT1RDTk9XbFYKc1lEbWlKa2xaRUZ3QWNqR0svdHFzQXMwZHZabnRyQ0p4OFRDMUtheWJGZTN5Q1B1RW52SzY2eEdJSkdNCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
service:
name: pg-bahrain.demo.svc
path: /
port: 3306
scheme: mysql
url: tcp(mysql-bahrain.demo.svc:3306)/
parameters:
apiVersion: appcatalog.appscode.com/v1alpha1
kind: StashAddon
stash:
addon:
backupTask:
name: mysql-backup-8.0.21
params:
- name: args
value: --all-databases --set-gtid-purged=OFF
restoreTask:
name: mysql-restore-8.0.21
secret:
name: mysql-bahrain-remote-replica-auth
tlsSecret:
name: mysql-bahrain-client-cert-remote
type: kubedb.com/mysql
version: 8.0.31
58 changes: 58 additions & 0 deletions pg-bahrain-remote-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: v1
kind: Secret
metadata:
creationTimestamp: null
name: pg-bahrain-remote-replica-auth
namespace: demo
stringData:
password: remote
username: remote
type: kubernetes.io/basic-auth
---
apiVersion: appcatalog.appscode.com/v1alpha1
kind: AppBinding
metadata:
creationTimestamp: "2023-09-25T13:36:30Z"
generation: 1
labels:
app.kubernetes.io/component: database
app.kubernetes.io/instance: pg-bahrain
app.kubernetes.io/managed-by: kubedb.com
app.kubernetes.io/name: postgreses.kubedb.com
name: pg-bahrain
namespace: demo
ownerReferences:
- apiVersion: kubedb.com/v1alpha2
blockOwnerDeletion: true
controller: true
kind: Postgres
name: pg-bahrain
uid: 58ee3104-6a61-4874-89ed-47f36ff40151
resourceVersion: "879894"
uid: 7dc01404-cd4f-4f2d-ae5b-481c894462d7
spec:
appRef:
apiGroup: kubedb.com
kind: Postgres
name: pg-bahrain
namespace: demo
clientConfig:
service:
name: pg-bahrain.demo.svc
path: /
port: 5432
query: sslmode=disable
scheme: postgresql
parameters:
apiVersion: appcatalog.appscode.com/v1alpha1
kind: StashAddon
stash:
addon:
backupTask:
name: postgres-backup-15.1
restoreTask:
name: postgres-restore-15.1
secret:
name: pg-bahrain-remote-replica-auth
type: kubedb.com/postgres
version: "15.3"
45 changes: 45 additions & 0 deletions pkg/cmds/remote_replica.go
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
}
6 changes: 6 additions & 0 deletions pkg/cmds/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ func NewKubeDBCommand(in io.Reader, out, err io.Writer) *cobra.Command {
NewCmdData(f),
},
},
{
Message: "Generate appbinding and secrets for remote Replica",
Commands: []*cobra.Command{
NewCmdGenApb(f),
},
},
}

filters := []string{"options"}
Expand Down
104 changes: 104 additions & 0 deletions pkg/common/mysql.go
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
}
Loading

0 comments on commit 20c2b28

Please sign in to comment.