diff --git a/README.md b/README.md index 0ea7d5a..f78bddc 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,10 @@ setting up an organization and an admin user. Additionally, it generates Kuberne | TYK_K8SBOOTSTRAP_TYK_ORG_NAME | corresponds to the name for your organization that is going to be bootstrapped in Tyk. | | TYK_K8SBOOTSTRAP_TYK_ORG_CNAME | corresponds to the Organisation CNAME which is going to bind the Portal to. | | TYK_K8SBOOTSTRAP_TYK_ORG_ID | corresponds to the organisation ID that is being created. | +| TYK_K8SBOOTSTRAP_TYK_ORG_HYBRID_ENABLED | specifies if the Hybrid organisation for MDCB Control Plane is enabled or not | +| TYK_K8SBOOTSTRAP_TYK_ORG_HYBRID_KEYEVENT | corresponds to `key_event` of the event options (optional). | +| TYK_K8SBOOTSTRAP_TYK_ORG_HYBRID_HASHEDKEYEVENT | corresponds to `hashed_key_event` of the event options (optional). | | TYK_K8SBOOTSTRAP_TYK_DASHBOARDLICENSE | corresponds to the license key of Tyk Dashboard. | -| TYK_K8SBOOTSTRAP_TYK_HYBRID_ENABLED | specifies if the Hybrid organisation for MDCB Control Plane is enabled or not | -| TYK_K8SBOOTSTRAP_TYK_HYBRID_KEYEVENT | corresponds to `key_event` of the event options (optional). | -| TYK_K8SBOOTSTRAP_TYK_HYBRID_HASHEDKEYEVENT | corresponds to `hashed_key_event` of the event options (optional). | ## Bootstrapped Environments diff --git a/hack/load_images.sh b/hack/load_images.sh index 1302ba2..58dd25d 100755 --- a/hack/load_images.sh +++ b/hack/load_images.sh @@ -2,11 +2,7 @@ make build-all -docker build -t tykio/tyk-k8s-bootstrap-pre-install:testing -f ./.container/image/bootstrap-pre-install/Dockerfile ./bin && - kind load docker-image tykio/tyk-k8s-bootstrap-pre-install:testing +docker build -t tykio/tyk-k8s-bootstrap-pre-install:testing -f ./.container/image/bootstrap-pre-install/Dockerfile ./bin +docker build -t tykio/tyk-k8s-bootstrap-post:testing -f ./.container/image/bootstrap-post/Dockerfile ./bin +docker build -t tykio/tyk-k8s-bootstrap-pre-delete:testing -f ./.container/image/bootstrap-pre-delete/Dockerfile ./bin -docker build -t tykio/tyk-k8s-bootstrap-post:testing -f ./.container/image/bootstrap-post/Dockerfile ./bin && - kind load docker-image tykio/tyk-k8s-bootstrap-post:testing - -docker build -t tykio/tyk-k8s-bootstrap-pre-delete:testing -f ./.container/image/bootstrap-pre-delete/Dockerfile ./bin && - kind load docker-image tykio/tyk-k8s-bootstrap-pre-delete:testing diff --git a/pkg/config/config.go b/pkg/config/config.go index cd922b4..99e649b 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -76,6 +76,9 @@ type TykOrg struct { // ID corresponds to the organisation ID that is being created. ID string + + // Hybrid includes details of hybrid organisation while using MDCB Control Plane + Hybrid *HybridConf } type TykConf struct { @@ -86,9 +89,6 @@ type TykConf struct { // DashboardLicense corresponds to the license key of Tyk Dashboard. DashboardLicense string - - // Hybrid includes details of hybrid organisation while using MDCB Control Plane - Hybrid HybridConf } type HybridConf struct { @@ -99,7 +99,7 @@ type HybridConf struct { KeyEvent *api.EventConfig // HashedKeyEvent corresponds to `hashed_key_event` of the event options which enables key events such as updates // and deletes, to be propagated to the various instance zones. - HashedKeyEvent *api.EventConfig + HashedKeyEvent *api.EventConfig `json:",omitempty"` } func NewConfig() (*Config, error) { diff --git a/tyk/api/request.go b/tyk/api/request.go index 83ecbc0..1f709b8 100644 --- a/tyk/api/request.go +++ b/tyk/api/request.go @@ -1,9 +1,9 @@ package api type EventConfig struct { - Webhook string `json:"webhook"` - Email string `json:"email"` - Redis bool `json:"redis"` + Webhook string `json:"webhook,omitempty"` + Email string `json:"email,omitempty"` + Redis bool `json:"redis,omitempty"` } type CreateOrgReq struct { @@ -11,7 +11,7 @@ type CreateOrgReq struct { CnameEnabled bool `json:"cname_enabled"` Cname string `json:"cname"` HybridEnabled bool `json:"hybrid_enabled"` - EventOptions map[string]EventConfig `json:"event_options"` + EventOptions map[string]EventConfig `json:"event_options,omitempty"` } type ResetPasswordReq struct { diff --git a/tyk/organisation.go b/tyk/organisation.go index 927e934..7dc1d06 100644 --- a/tyk/organisation.go +++ b/tyk/organisation.go @@ -82,9 +82,9 @@ func (s *Service) CreateOrganisation() error { // Enable hybrid in the organisation while setting up the MDCB Control Plane. // For reference: https://tyk.io/docs/tyk-multi-data-centre/setup-controller-data-centre/ - if s.appArgs.Tyk.Hybrid.Enabled { + if s.appArgs.Tyk.Org.Hybrid != nil && s.appArgs.Tyk.Org.Hybrid.Enabled { createOrgData.HybridEnabled = true - createOrgData.EventOptions = eventOptions(s.appArgs.Tyk.Hybrid, s.appArgs.Tyk.Admin.EmailAddress) + createOrgData.EventOptions = eventOptions(s.appArgs.Tyk.Org.Hybrid, s.appArgs.Tyk.Admin.EmailAddress) } reqBodyBytes, err := json.Marshal(createOrgData) @@ -130,25 +130,39 @@ func (s *Service) CreateOrganisation() error { return nil } -func eventOptions(hconf config.HybridConf, defaultEmail string) map[string]api.EventConfig { +func eventOptions(hconf *config.HybridConf, defaultEmail string) map[string]api.EventConfig { + if hconf == nil { + return nil + } + m := make(map[string]api.EventConfig) const ( - keyEventKey = "key_event" hashedKeyEventKey = "hashed_key_event" + keyEventKey = "key_event" ) + hashedKeyEventConf := api.EventConfig{ + Email: defaultEmail, + Webhook: hconf.HashedKeyEvent.Webhook, + Redis: hconf.HashedKeyEvent.Redis, + } + keyEventConf := hashedKeyEventConf + if hconf.HashedKeyEvent != nil { - m[hashedKeyEventKey] = *hconf.HashedKeyEvent - } else { - m[hashedKeyEventKey] = api.EventConfig{Email: defaultEmail} + if hconf.HashedKeyEvent.Email != "" { + hashedKeyEventConf.Email = hconf.HashedKeyEvent.Email + } } if hconf.KeyEvent != nil { - m[keyEventKey] = *hconf.KeyEvent - } else { - m[keyEventKey] = api.EventConfig{Email: defaultEmail} + if hconf.KeyEvent.Email != "" { + keyEventConf.Email = hconf.KeyEvent.Email + } } + m[hashedKeyEventKey] = hashedKeyEventConf + m[keyEventKey] = keyEventConf + return m }