Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Get only first cluster for watch CRD MultiCassKop #156

Merged
merged 24 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7f77aae
Get only first cluster for watch CRD MultiCassKop
Dec 16, 2019
49bd2a7
add master var in cluster struct to identify it properly
Dec 17, 2019
ed0a181
review clusters struct
Dec 18, 2019
fe1372c
refactor clients & clusters definition, to expose master & remotes co…
Dec 20, 2019
5badfcd
Prepend remotes with master, to keep logic with seed list.
Dec 20, 2019
3b47092
Rename master to local, to be consistent with helm variables
Dec 20, 2019
0cedc50
Rename master to local, to be consistent with helm variables
Dec 20, 2019
14acb2b
change remote & local declaration using flags in command line, to exp…
Dec 20, 2019
5f5bd3f
Merge pull request #1 from erdrix/watch-crd-improved
Dec 20, 2019
d6eaa71
Get only first cluster for watch CRD MultiCassKop
Dec 16, 2019
6671510
add master var in cluster struct to identify it properly
Dec 17, 2019
2666003
review clusters struct
Dec 18, 2019
fd3c49a
refactor clients & clusters definition, to expose master & remotes co…
Dec 20, 2019
efc1bc6
Prepend remotes with master, to keep logic with seed list.
Dec 20, 2019
77b3d93
Rename master to local, to be consistent with helm variables
Dec 20, 2019
fe5c9ff
Rename master to local, to be consistent with helm variables
Dec 20, 2019
5b08ac8
change remote & local declaration using flags in command line, to exp…
Dec 20, 2019
c740a0e
Merge branch 'watch-crd' of /~https://github.com/erdrix/cassandra-k8s-o…
Dec 20, 2019
8b6efe7
minor updates
Dec 20, 2019
850cea6
update minor
Dec 20, 2019
ebfbbbe
Add watch on CassandraCluster resources for remotes cluster into admi…
Dec 21, 2019
1d4bb3f
minor update
Dec 26, 2019
44deb93
remove telepresence env file
Jan 6, 2020
e12d56c
correct comments
Jan 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ debug
.idea/
.vscode
cassandra-operator.env
multi-casskop/multi-casskop.env
telepresence.log
build/_output
pkg/apis/db/v1alpha1/zz_generated.deepcopy.go
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
admiralty.io/multicluster-controller v0.2.0 // indirect
admiralty.io/multicluster-service-account v0.6.0 // indirect
contrib.go.opencensus.io/exporter/ocagent v0.4.12 // indirect
github.com/NYTimes/gziphandler v1.0.1 // indirect
github.com/allamand/godebug v0.0.0-20190404121221-3ec752cd7166
github.com/banzaicloud/k8s-objectmatcher v1.0.1
github.com/emicklei/go-restful v2.9.6+incompatible // indirect
Expand Down
2 changes: 1 addition & 1 deletion multi-casskop/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ build-local:
debug-telepresence:
export TELEPRESENCE_REGISTRY=$(TELEPRESENCE_REGISTRY) ; \
echo "execute : cat multi-casskop.env" ; \
sudo mkdir -p /vear/run/secrets/kubernetes.io ; \
sudo mkdir -p /var/run/secrets/kubernetes.io ; \
sudo mkdir -p /var/run/secrets/admiralty.io ; \
sudo ln -s /tmp/known/var/run/secrets/kubernetes.io/serviceaccount /var/run/secrets/kubernetes.io/ ; \
sudo ln -s /tmp/known/var/run/secrets/admiralty.io/serviceaccountimports /var/run/secrets/admiralty.io/ ; \
Expand Down
Binary file modified multi-casskop/build/_output/bin/multi-casskop
Binary file not shown.
76 changes: 50 additions & 26 deletions multi-casskop/cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ limitations under the License.
package main

import (
"flag"
"github.com/Orange-OpenSource/cassandra-k8s-operator/multi-casskop/pkg/controller/multi-casskop/models"
// "flag"
"github.com/jessevdk/go-flags"
"log"
"os"
"strings"
Expand Down Expand Up @@ -58,6 +60,21 @@ func getLogLevel() logrus.Level {
return logrus.InfoLevel
}

type Options struct {
// Slice of bool will append 'true' each time the option
// is encountered (can be set multiple times, like -vvv)
Verbose []bool `short:"v" long:"verbose" description:"Show verbose debug information"`

Local string `short:"l" description:"The local k8s cluster name"`

// Example of a slice of strings
Remotes []string `short:"r" description:"The remotes k8S cluster name list"`
}

var opts Options

var parser = flags.NewParser(&opts, flags.Default)

func main() {

logType, found := os.LookupEnv("LOG_TYPE")
Expand All @@ -66,44 +83,51 @@ func main() {
}
logrus.SetLevel(getLogLevel())

flag.Parse()
if flag.NArg() < 1 {
log.Fatalf("Usage: MultiCasskop cluster-1 cluster-2 .. cluster-n")
if _, err := parser.Parse(); err != nil {
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp {
os.Exit(0)
} else {
os.Exit(1)
}
}

var clusters []mc.Clusters
var clusters models.Clusters

namespace, err := k8sutil.GetWatchNamespace()
if err != nil {
logrus.Fatalf("failed to get watch namespace: %v", err)
}

for i := 0; i < flag.NArg(); i++ {
clusterName := flag.Arg(i)
// Configuring Local cluster
logrus.Infof("Configuring Client for local cluster %s. using local k8s api access",
opts.Local)

cfg, err := kconfig.GetConfig()
if err != nil {
logrus.Error(err)
os.Exit(1)
}
// Set up local cluster
clusters.Local = &models.Cluster{Name: opts.Local, Cluster: cluster.New(opts.Local, cfg,
cluster.Options{CacheOptions: cluster.CacheOptions{Namespace: namespace}})}

// Configuring Remotes clusters
for i, remote := range opts.Remotes {

var cfg *rest.Config
var err error

if i == 0 {
logrus.Infof("Configuring Client %d for local cluster %s (first in arg list). using local k8s api access",
i+1, clusterName)
cfg, err = kconfig.GetConfig()
if err != nil {
logrus.Error(err)
os.Exit(1)
}
} else {
logrus.Infof("Configuring Client %d for distant cluster %s. using imported secret of same name", i+1,
clusterName)
cfg, _, err = config.NamedConfigAndNamespace(clusterName)
if err != nil {
log.Fatal(err)
}

logrus.Infof("Configuring Client %d for remote cluster %s. using imported secret of same name", i+1,
remote)
cfg, _, err = config.NamedConfigAndNamespace(remote)
if err != nil {
log.Fatal(err)
}
clusters = append(clusters,
mc.Clusters{Name: clusterName, Cluster: cluster.New(clusterName, cfg,
cluster.Options{CacheOptions: cluster.CacheOptions{Namespace: namespace}})})

// Set up Remotes clusters
clusters.Remotes = append(clusters.Remotes,
&models.Cluster{Name: remote, Cluster: cluster.New(remote, cfg,
cluster.Options{CacheOptions: cluster.CacheOptions{Namespace: namespace}})})
}

logrus.Info("Creating Controller")
Expand Down
10 changes: 0 additions & 10 deletions multi-casskop/docs/tutorials/gke.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,6 @@ gke-slave-west1-c Opaque 5 28

### Install Multi-CassKop

@TODO : To correct once the watch object will be fixed

Add MultiCasskop crd on the `slave` cluster :

```sh
$ kubectx # Switch context on slave cluster
Switched to context "gke_<Project name>_europe-west1-c_cassandra-europe-west1-c-slave".
$ kubectl apply -f https://raw.githubusercontent.com/Orange-OpenSource/cassandra-k8s-operator/master/multi-casskop/deploy/crds/multicluster_v1alpha1_cassandramulticluster_crd.yaml
```

@TODO : To correct once the helm release and docker image will be properly deployed
Deployment with Helm :

Expand Down
1 change: 1 addition & 0 deletions multi-casskop/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/imdario/mergo v0.3.8
github.com/jessevdk/go-flags v1.4.0
github.com/kylelemons/godebug v1.1.0
github.com/operator-framework/operator-sdk v0.10.0
github.com/sirupsen/logrus v1.4.2
Expand Down
14 changes: 2 additions & 12 deletions multi-casskop/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
admiralty.io/multicluster-controller v0.2.0 h1:ajPasPVjeT9gKI9egEUhZOWXIkJZAZJw4r1f1gSovhI=
admiralty.io/multicluster-controller v0.2.0/go.mod h1:hpWrIHZz6R7rHbm034MouEbhMIs4B4L1AlBeaK9dvfE=
admiralty.io/multicluster-service-account v0.5.1 h1:SIEQsiepKkXeE7svyGgreII331sSvlWMfLBSEbule+w=
admiralty.io/multicluster-service-account v0.5.1/go.mod h1:fkgbwbknpY4gCmZwAkmy7I+H9GNqE30/HIldfoOOAH0=
admiralty.io/multicluster-service-account v0.6.0 h1:6K428vEadhWZWacXuGUJXT9mJH2PG2yLbXDmTwPm+Vk=
admiralty.io/multicluster-service-account v0.6.0/go.mod h1:V6XeGFNGhtgzFVnI+49Ur5pLWzwJQmAKLt+IiK4gvxI=
bitbucket.org/ww/goautoneg v0.0.0-20120707110453-75cd24fc2f2c/go.mod h1:1vhO7Mn/FZMgOgDVGLy5X1mE6rq1HbkBdkF/yj8zkcg=
Expand Down Expand Up @@ -152,7 +150,6 @@ github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nA
github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
github.com/go-openapi/spec v0.17.2/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
github.com/go-openapi/spec v0.19.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY=
github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
github.com/go-openapi/strfmt v0.17.2/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
Expand All @@ -161,7 +158,6 @@ github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dp
github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
github.com/go-openapi/swag v0.19.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.3/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/validate v0.17.2/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
Expand Down Expand Up @@ -408,15 +404,15 @@ github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80s
github.com/jackc/pgx v3.2.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I=
github.com/jarcoal/httpmock v1.0.4/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jmoiron/sqlx v0.0.0-20180614180643-0dae4fefe7c0/go.mod h1:IiEW3SEiiErVyFdH8NTuWjSifiEQKUoyK3LNqr2kCHU=
github.com/joho/godotenv v1.2.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46Ok=
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
Expand Down Expand Up @@ -728,7 +724,6 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190812203447-cdfb69ac37fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191007182048-72f939374954 h1:JGZucVF/L/TotR719NbujzadOZ2AgnYlqphQGHDCKaU=
Expand Down Expand Up @@ -838,7 +833,6 @@ golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgw
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190703212419-2214986f1668/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down Expand Up @@ -938,7 +932,6 @@ k8s.io/client-go v0.0.0-20190228174230-b40b2a5939e4 h1:aE8wOCKuoRs2aU0OP/Rz8SXiA
k8s.io/client-go v0.0.0-20190228174230-b40b2a5939e4/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
k8s.io/code-generator v0.0.0-20181203235156-f8cba74510f3/go.mod h1:MYiN+ZJZ9HkETbgVZdWw2AsuAi9PZ4V80cwfuf2axe8=
k8s.io/code-generator v0.0.0-20181206115026-3a2206dd6a78/go.mod h1:MYiN+ZJZ9HkETbgVZdWw2AsuAi9PZ4V80cwfuf2axe8=
k8s.io/code-generator v0.0.0-20191003035328-700b1226c0bd/go.mod h1:HC9p4y3SBN+txSs8x57qmNPXFZ/CxdCHiDTNnocCSEw=
k8s.io/code-generator v0.0.0-20191121015212-c4c8f8345c7e/go.mod h1:DVmfPQgxQENqDIzVR2ddLXMH34qeszkKSdH/N+s+38s=
k8s.io/gengo v0.0.0-20181106084056-51747d6e00da/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20181113154421-fd15ee9cc2f7/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
Expand All @@ -960,14 +953,11 @@ k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd/go.mod h1:BXM9ceUBTj2QnfH
k8s.io/kube-openapi v0.0.0-20181114233023-0317810137be/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
k8s.io/kube-openapi v0.0.0-20190320154901-5e45bb682580/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
k8s.io/kube-openapi v0.0.0-20190722073852-5e22f3d471e6/go.mod h1:RZvgC8MSN6DjiMV6oIfEE9pDL9CYXokkfaCKZeHm3nc=
k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
k8s.io/kube-state-metrics v1.6.0/go.mod h1:84+q9aGVQPzXYGgtvyhZr/fSI6BdLsbPWXn37RASc9k=
k8s.io/kubernetes v1.11.7-beta.0.0.20181219023948-b875d52ea96d/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
k8s.io/kubernetes v1.11.8-beta.0.0.20190124204751-3a10094374f2/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
k8s.io/sample-controller v0.0.0-20181221200518-c3a5aa93b2bf/go.mod h1:ulrg2qtVB4979TuA1BhaD/oGPZxO5NRWwHbk2FgaC3g=
k8s.io/sample-controller v0.0.0-20191005120943-ac9726f261cc h1:CPR3VXKSLXc1Db6M59sbIu4HhZnibP5RcLgmhQ37wOE=
k8s.io/sample-controller v0.0.0-20191005120943-ac9726f261cc/go.mod h1:Z7xuoA0fEIdUaVimPbdvkPP9oxJMoe5Oj+H8VmZHFc4=
k8s.io/sample-controller v0.0.0-20191121021213-d454fe81777c h1:f9d7+bXBQOPt1ltrnQbiYIOqCH1xJc0xGD43/wsTEyU=
k8s.io/sample-controller v0.0.0-20191121021213-d454fe81777c/go.mod h1:rEpnZYUTa54dFNGuJ5bTK2PkALnC0/GkGekw2GuTf5E=
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7/go.mod h1:8k8uAuAQ0rXslZKaEWd0c3oVhZz7sSzSiPnVZayjIX0=
Expand Down
4 changes: 2 additions & 2 deletions multi-casskop/helm/multi-casskop/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ spec:
- {{ .Values.command }}
{{- end }}
args:
- {{ .Values.k8s.local }}
- -l{{ .Values.k8s.local }}
{{- range .Values.k8s.remote }}
- {{ . }}
- -r{{ . }}
{{- end }}
readinessProbe:
exec:
Expand Down
25 changes: 13 additions & 12 deletions multi-casskop/pkg/controller/multi-casskop/cmc_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package multicasskop

import (
"context"
"github.com/Orange-OpenSource/cassandra-k8s-operator/multi-casskop/pkg/controller/multi-casskop/models"

ccv1 "github.com/Orange-OpenSource/cassandra-k8s-operator/pkg/apis/db/v1alpha1"
"github.com/kylelemons/godebug/pretty"
Expand Down Expand Up @@ -35,14 +36,14 @@ func (r *reconciler) GetCassandraCluster(client *Client, cc *ccv1.CassandraClust

// CreateOrUpdateCassandraCluster
// create CassandraCluster object in target kubernetes cluster if not exists
// update it if it already existe
func (r *reconciler) CreateOrUpdateCassandraCluster(client *Client,
// update it if it already exist
func (r *reconciler) CreateOrUpdateCassandraCluster(client *models.Client,
cc *ccv1.CassandraCluster) (bool, *ccv1.CassandraCluster, error) {
storedCC := &ccv1.CassandraCluster{}

if err := client.client.Get(context.TODO(), r.namespacedName(cc.Name, cc.Namespace), storedCC); err != nil {
if err := client.Client.Get(context.TODO(), r.namespacedName(cc.Name, cc.Namespace), storedCC); err != nil {
if errors.IsNotFound(err) {
logrus.WithFields(logrus.Fields{"cluster": cc.Name, "namespace": cc.Namespace, "kubernetes": client.name}).Debug("CassandraCluster don't exists, we create it ")
logrus.WithFields(logrus.Fields{"cluster": cc.Name, "namespace": cc.Namespace, "kubernetes": client.Name}).Debug("CassandraCluster don't exists, we create it ")
newCC, err := r.CreateCassandraCluster(client, cc)
return true, newCC, err
}
Expand All @@ -52,7 +53,7 @@ func (r *reconciler) CreateOrUpdateCassandraCluster(client *Client,
needUpdate := false
//TODO: need new way to detect changes
if !apiequality.Semantic.DeepEqual(storedCC.Spec, cc.Spec) {
logrus.WithFields(logrus.Fields{"cluster": cc.Name, "namespace": cc.Namespace, "kubernetes": client.name}).
logrus.WithFields(logrus.Fields{"cluster": cc.Name, "namespace": cc.Namespace, "kubernetes": client.Name}).
Info("CassandraCluster is different: " + pretty.Compare(storedCC.Spec, cc.Spec))
storedCC.Spec = cc.Spec
needUpdate = true
Expand All @@ -63,7 +64,7 @@ func (r *reconciler) CreateOrUpdateCassandraCluster(client *Client,

if cc.Status.SeedList != nil &&
!apiequality.Semantic.DeepEqual(storedCC.Status.SeedList, cc.Status.SeedList) {
logrus.WithFields(logrus.Fields{"cluster": cc.Name, "namespace": cc.Namespace, "kubernetes": client.name}).
logrus.WithFields(logrus.Fields{"cluster": cc.Name, "namespace": cc.Namespace, "kubernetes": client.Name}).
Info("SeedList is different: " + pretty.Compare(storedCC.Status.SeedList, cc.Status.SeedList))
storedCC.Status.SeedList = cc.Status.SeedList
needUpdate = true
Expand All @@ -76,21 +77,21 @@ func (r *reconciler) CreateOrUpdateCassandraCluster(client *Client,
return false, storedCC, nil
}

func (r *reconciler) CreateCassandraCluster(client *Client, cc *ccv1.CassandraCluster) (*ccv1.CassandraCluster, error) {
func (r *reconciler) CreateCassandraCluster(client *models.Client, cc *ccv1.CassandraCluster) (*ccv1.CassandraCluster, error) {
var err error
logrus.WithFields(logrus.Fields{"cluster": cc.Name, "namespace": cc.Namespace, "kubernetes": client.name}).Debug("Create CassandraCluster")
if err = client.client.Create(context.TODO(), cc); err != nil {
logrus.WithFields(logrus.Fields{"cluster": cc.Name, "namespace": cc.Namespace, "kubernetes": client.Name}).Debug("Create CassandraCluster")
if err = client.Client.Create(context.TODO(), cc); err != nil {
if errors.IsAlreadyExists(err) {
return cc, nil
}
}
return cc, err
}

func (r *reconciler) UpdateCassandraCluster(client *Client, cc *ccv1.CassandraCluster) (*ccv1.CassandraCluster, error) {
func (r *reconciler) UpdateCassandraCluster(client *models.Client, cc *ccv1.CassandraCluster) (*ccv1.CassandraCluster, error) {
var err error
logrus.WithFields(logrus.Fields{"cluster": cc.Name, "namespace": cc.Namespace, "kubernetes": client.name}).Debug("Update CassandraCluster")
if err = client.client.Update(context.TODO(), cc); err != nil {
logrus.WithFields(logrus.Fields{"cluster": cc.Name, "namespace": cc.Namespace, "kubernetes": client.Name}).Debug("Update CassandraCluster")
if err = client.Client.Update(context.TODO(), cc); err != nil {
if errors.IsAlreadyExists(err) {
return cc, nil
}
Expand Down
37 changes: 37 additions & 0 deletions multi-casskop/pkg/controller/multi-casskop/models/clients.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2019 Orange
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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 models

import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// Client is the k8s client to use to connect to each kubernetes
type Client struct {
Name string
Client client.Client
}

// Clients defined each client (local & remotes) to access to k8s cluster.
type Clients struct {
Local *Client
Remotes []*Client
}

// Convert local & remotes clients to a merged list.
// Simplify loop on clients
func (clients *Clients) FlatClients() []*Client {
flatClients := append([]*Client{clients.Local}, clients.Remotes...)
return flatClients
}
Loading