Skip to content

Commit da591d0

Browse files
author
Jeff McCormick
committed
clone is working at this commit
1 parent b531c0b commit da591d0

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

operator/cluster/cluster_strategy_1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (r ClusterStrategy1) AddCluster(clientset *kubernetes.Clientset, client *re
159159
}
160160
log.Info("created master Deployment " + deploymentResult.Name + " in namespace " + namespace)
161161
} else {
162-
log.Info("master Deployment " + deploymentResult.Name + " in namespace " + namespace + " already existed so not creating it ")
162+
log.Info("master Deployment " + cl.Spec.Name + " in namespace " + namespace + " already existed so not creating it ")
163163
}
164164

165165
//create the replica deployment

operator/postgres-operator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func main() {
9696
go upgrade.Process(clientset, tprclient, stopchan, namespace)
9797
go upgrade.MajorUpgradeProcess(clientset, tprclient, stopchan, namespace)
9898
go cluster.ProcessClone(clientset, tprclient, stopchan, namespace)
99-
go cluster.CompleteClone(clientset, tprclient, stopchan, namespace)
99+
go cluster.CompleteClone(config, clientset, tprclient, stopchan, namespace)
100100

101101
signals := make(chan os.Signal, 1)
102102
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)

operator/util/exec.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/gorilla/websocket"
2323
"io"
2424
"k8s.io/client-go/rest"
25+
//"k8s.io/client-go/tools/clientcmd"
2526
"net/http"
2627
"net/url"
2728
)
@@ -34,13 +35,7 @@ type WebsocketRoundTripper struct {
3435
}
3536

3637
//execs the cmd
37-
func Exec(namespace, podname, containername, cmd string) error {
38-
39-
config, err := rest.InClusterConfig()
40-
if err != nil {
41-
log.Error(err.Error())
42-
return err
43-
}
38+
func Exec(config *rest.Config, namespace, podname, containername string, cmd []string) error {
4439

4540
wrappedRoundTripper, err := roundTripperFromConfig(config)
4641
if err != nil {
@@ -98,8 +93,9 @@ func roundTripperFromConfig(config *rest.Config) (http.RoundTripper, error) {
9893
return rest.HTTPWrappersForConfig(config, rt)
9994
}
10095

101-
func requestFromConfig(config *rest.Config, pod string, container string, namespace string, cmd string) (*http.Request, error) {
96+
func requestFromConfig(config *rest.Config, pod string, container string, namespace string, cmd []string) (*http.Request, error) {
10297

98+
log.Info("config.Host is " + config.Host)
10399
u, err := url.Parse(config.Host)
104100
if err != nil {
105101
return nil, err
@@ -115,11 +111,18 @@ func requestFromConfig(config *rest.Config, pod string, container string, namesp
115111
}
116112

117113
u.Path = fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/exec", namespace, pod)
118-
if container != "" {
119-
u.RawQuery = "command=" + cmd +
120-
"&container=" + container +
121-
"&stderr=true&stdout=true"
114+
params := url.Values{}
115+
for _, v := range cmd {
116+
params.Add("command", v)
122117
}
118+
params.Add("container", container)
119+
params.Add("stderr", "true")
120+
params.Add("stdout", "true")
121+
122+
u.RawQuery = params.Encode()
123+
124+
log.Info(u.String())
125+
123126
req := &http.Request{
124127
Method: http.MethodGet,
125128
URL: u,

operator/util/secrets.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"k8s.io/client-go/pkg/api/v1"
2727
"math/rand"
28+
"strings"
2829
"time"
2930
)
3031

@@ -173,3 +174,35 @@ func GetPasswordFromSecret(clientset *kubernetes.Clientset, namespace string, se
173174
return string(secret.Data["password"][:]), err
174175

175176
}
177+
178+
func CopySecrets(clientset *kubernetes.Clientset, namespace string, fromCluster, toCluster string) error {
179+
180+
log.Debug("CopySecrets " + fromCluster + " to " + toCluster)
181+
lo := v1.ListOptions{LabelSelector: "pg-database=" + fromCluster}
182+
secrets, err := clientset.Secrets(namespace).List(lo)
183+
if err != nil {
184+
log.Error("error getting list of secrets" + err.Error())
185+
return err
186+
}
187+
188+
for _, s := range secrets.Items {
189+
log.Debug("found secret : " + s.ObjectMeta.Name)
190+
secret := v1.Secret{}
191+
secret.Name = strings.Replace(s.ObjectMeta.Name, fromCluster, toCluster, 1)
192+
secret.ObjectMeta.Labels = make(map[string]string)
193+
secret.ObjectMeta.Labels["pg-database"] = toCluster
194+
secret.Data = make(map[string][]byte)
195+
secret.Data["username"] = s.Data["username"][:]
196+
secret.Data["password"] = s.Data["password"][:]
197+
198+
_, err := clientset.Secrets(namespace).Create(&secret)
199+
if err != nil {
200+
log.Error("error creating secret" + err.Error())
201+
} else {
202+
log.Info("created secret " + secret.Name)
203+
}
204+
205+
}
206+
return err
207+
208+
}

0 commit comments

Comments
 (0)