Skip to content

Commit

Permalink
Merge pull request #204 from 3scale/new-reconcile-approach
Browse files Browse the repository at this point in the history
Specific CR field reconciliation pattern implementation approach
  • Loading branch information
eguzki authored Sep 6, 2019
2 parents 674b70a + 9f0fcf8 commit 8049224
Show file tree
Hide file tree
Showing 42 changed files with 1,634 additions and 1,858 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/go-openapi/strfmt v0.19.0 // indirect
github.com/go-openapi/validate v0.19.0 // indirect
github.com/golang/groupcache v0.0.0-20180924190550-6f2cf27854a4 // indirect
github.com/google/go-cmp v0.2.0
github.com/google/go-cmp v0.3.0
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/gophercloud/gophercloud v0.0.0-20190318015731-ff9851476e98 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
Expand Down
37 changes: 0 additions & 37 deletions go.sum

Large diffs are not rendered by default.

46 changes: 24 additions & 22 deletions pkg/3scale/amp/component/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,19 @@ func (backend *Backend) WorkerDeploymentConfig() *appsv1.DeploymentConfig {
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"threescale_component": "backend", "threescale_component_element": "worker", "app": backend.Options.appLabel, "deploymentConfig": "backend-worker"},
},
Spec: v1.PodSpec{InitContainers: []v1.Container{
v1.Container{
Name: "backend-redis-svc",
Image: "amp-backend:latest",
Command: []string{
"/opt/app/entrypoint.sh",
"sh",
"-c",
"until rake connectivity:redis_storage_queue_check; do sleep $SLEEP_SECONDS; done",
}, Env: append(backend.buildBackendCommonEnv(), envVarFromValue("SLEEP_SECONDS", "1")),
Spec: v1.PodSpec{
InitContainers: []v1.Container{
v1.Container{
Name: "backend-redis-svc",
Image: "amp-backend:latest",
Command: []string{
"/opt/app/entrypoint.sh",
"sh",
"-c",
"until rake connectivity:redis_storage_queue_check; do sleep $SLEEP_SECONDS; done",
}, Env: append(backend.buildBackendCommonEnv(), envVarFromValue("SLEEP_SECONDS", "1")),
},
},
},
Containers: []v1.Container{
v1.Container{
Name: "backend-worker",
Expand Down Expand Up @@ -181,18 +182,19 @@ func (backend *Backend) CronDeploymentConfig() *appsv1.DeploymentConfig {
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"threescale_component": "backend", "threescale_component_element": "cron", "app": backend.Options.appLabel, "deploymentConfig": "backend-cron"},
},
Spec: v1.PodSpec{InitContainers: []v1.Container{
v1.Container{
Name: "backend-redis-svc",
Image: "amp-backend:latest",
Command: []string{
"/opt/app/entrypoint.sh",
"sh",
"-c",
"until rake connectivity:redis_storage_queue_check; do sleep $SLEEP_SECONDS; done",
}, Env: append(backend.buildBackendCommonEnv(), envVarFromValue("SLEEP_SECONDS", "1")),
Spec: v1.PodSpec{
InitContainers: []v1.Container{
v1.Container{
Name: "backend-redis-svc",
Image: "amp-backend:latest",
Command: []string{
"/opt/app/entrypoint.sh",
"sh",
"-c",
"until rake connectivity:redis_storage_queue_check; do sleep $SLEEP_SECONDS; done",
}, Env: append(backend.buildBackendCommonEnv(), envVarFromValue("SLEEP_SECONDS", "1")),
},
},
},
Containers: []v1.Container{
v1.Container{
Name: "backend-cron",
Expand Down
32 changes: 16 additions & 16 deletions pkg/3scale/amp/component/backend_options_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,36 +56,36 @@ func (m *BackendOptionsBuilder) WildcardDomain(wildcardDomain string) {
m.options.wildcardDomain = wildcardDomain
}

func (m *BackendOptionsBuilder) ListenerServiceEndpoint(serviceEndpoint string) {
m.options.serviceEndpoint = &serviceEndpoint
func (m *BackendOptionsBuilder) ListenerServiceEndpoint(serviceEndpoint *string) {
m.options.serviceEndpoint = serviceEndpoint
}

func (m *BackendOptionsBuilder) ListenerRouteEndpoint(routeEndpoint string) {
m.options.routeEndpoint = &routeEndpoint
func (m *BackendOptionsBuilder) ListenerRouteEndpoint(routeEndpoint *string) {
m.options.routeEndpoint = routeEndpoint
}

func (m *BackendOptionsBuilder) RedisStorageURL(url string) {
m.options.storageURL = &url
func (m *BackendOptionsBuilder) RedisStorageURL(url *string) {
m.options.storageURL = url
}

func (m *BackendOptionsBuilder) RedisQueuesURL(url string) {
m.options.queuesURL = &url
func (m *BackendOptionsBuilder) RedisQueuesURL(url *string) {
m.options.queuesURL = url
}

func (m *BackendOptionsBuilder) RedisStorageSentinelHosts(hosts string) {
m.options.storageSentinelHosts = &hosts
func (m *BackendOptionsBuilder) RedisStorageSentinelHosts(hosts *string) {
m.options.storageSentinelHosts = hosts
}

func (m *BackendOptionsBuilder) RedisStorageSentinelRole(role string) {
m.options.storageSentinelRole = &role
func (m *BackendOptionsBuilder) RedisStorageSentinelRole(role *string) {
m.options.storageSentinelRole = role
}

func (m *BackendOptionsBuilder) RedisQueuesSentinelHosts(hosts string) {
m.options.queuesSentinelHosts = &hosts
func (m *BackendOptionsBuilder) RedisQueuesSentinelHosts(hosts *string) {
m.options.queuesSentinelHosts = hosts
}

func (m *BackendOptionsBuilder) RedisQueuesSentinelRole(role string) {
m.options.queuesSentinelRole = &role
func (m *BackendOptionsBuilder) RedisQueuesSentinelRole(role *string) {
m.options.queuesSentinelRole = role
}

func (m *BackendOptionsBuilder) ListenerResourceRequirements(resourceRequirements v1.ResourceRequirements) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/3scale/amp/component/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (system *System) buildSystemBaseEnv() []v1.EnvVar {
smtpEnvConfigMapEnvs := system.getSystemSmtpEnvsFromSMTPConfigMap()
result = append(result, smtpEnvConfigMapEnvs...)

apicastAccessToken := envVarFromSecret("APICAST_ACCESS_TOKEN", "system-master-apicast", "ACCESS_TOKEN")
apicastAccessToken := envVarFromSecret("APICAST_ACCESS_TOKEN", SystemSecretSystemMasterApicastSecretName, "ACCESS_TOKEN")
result = append(result, apicastAccessToken)

// Add zync secret to envvars sources
Expand Down
52 changes: 26 additions & 26 deletions pkg/3scale/amp/component/system_options_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func (s *SystemOptionsBuilder) AdminUsername(adminUsername string) {
s.options.adminUsername = adminUsername
}

func (s *SystemOptionsBuilder) AdminEmail(adminEmail string) {
s.options.adminEmail = &adminEmail
func (s *SystemOptionsBuilder) AdminEmail(adminEmail *string) {
s.options.adminEmail = adminEmail
}

func (s *SystemOptionsBuilder) AmpRelease(ampRelease string) {
Expand Down Expand Up @@ -148,52 +148,52 @@ func (s *SystemOptionsBuilder) StorageClassName(storageClassName *string) {
s.options.storageClassName = storageClassName
}

func (s *SystemOptionsBuilder) MemcachedServers(servers string) {
s.options.memcachedServers = &servers
func (s *SystemOptionsBuilder) MemcachedServers(servers *string) {
s.options.memcachedServers = servers
}

func (s *SystemOptionsBuilder) EventHooksURL(eventHooksURL string) {
s.options.eventHooksURL = &eventHooksURL
func (s *SystemOptionsBuilder) EventHooksURL(eventHooksURL *string) {
s.options.eventHooksURL = eventHooksURL
}

func (s *SystemOptionsBuilder) RedisURL(redisURL string) {
s.options.redisURL = &redisURL
func (s *SystemOptionsBuilder) RedisURL(redisURL *string) {
s.options.redisURL = redisURL
}

func (s *SystemOptionsBuilder) RedisSentinelHosts(hosts string) {
s.options.redisSentinelHosts = &hosts
func (s *SystemOptionsBuilder) RedisSentinelHosts(hosts *string) {
s.options.redisSentinelHosts = hosts
}

func (s *SystemOptionsBuilder) RedisSentinelRole(role string) {
s.options.redisSentinelRole = &role
func (s *SystemOptionsBuilder) RedisSentinelRole(role *string) {
s.options.redisSentinelRole = role
}

func (s *SystemOptionsBuilder) MessageBusRedisURL(url string) {
s.options.messageBusRedisURL = &url
func (s *SystemOptionsBuilder) MessageBusRedisURL(url *string) {
s.options.messageBusRedisURL = url
}

func (s *SystemOptionsBuilder) MessageBusRedisSentinelHosts(hosts string) {
s.options.messageBusRedisSentinelHosts = &hosts
func (s *SystemOptionsBuilder) MessageBusRedisSentinelHosts(hosts *string) {
s.options.messageBusRedisSentinelHosts = hosts
}

func (s *SystemOptionsBuilder) MessageBusRedisSentinelRole(role string) {
s.options.messageBusRedisSentinelRole = &role
func (s *SystemOptionsBuilder) MessageBusRedisSentinelRole(role *string) {
s.options.messageBusRedisSentinelRole = role
}

func (s *SystemOptionsBuilder) RedisNamespace(namespace string) {
s.options.redisNamespace = &namespace
func (s *SystemOptionsBuilder) RedisNamespace(namespace *string) {
s.options.redisNamespace = namespace
}

func (s *SystemOptionsBuilder) MessageBusRedisNamespace(namespace string) {
s.options.messageBusRedisNamespace = &namespace
func (s *SystemOptionsBuilder) MessageBusRedisNamespace(namespace *string) {
s.options.messageBusRedisNamespace = namespace
}

func (s *SystemOptionsBuilder) ApicastSystemMasterProxyConfigEndpoint(endpoint string) {
s.options.apicastSystemMasterProxyConfigEndpoint = &endpoint
func (s *SystemOptionsBuilder) ApicastSystemMasterProxyConfigEndpoint(endpoint *string) {
s.options.apicastSystemMasterProxyConfigEndpoint = endpoint
}

func (s *SystemOptionsBuilder) ApicastSystemMasterBaseURL(url string) {
s.options.apicastSystemMasterBaseURL = &url
func (s *SystemOptionsBuilder) ApicastSystemMasterBaseURL(url *string) {
s.options.apicastSystemMasterBaseURL = url
}

func (s *SystemOptionsBuilder) AppMasterContainerResourceRequirements(resourceRequirements v1.ResourceRequirements) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/3scale/amp/component/zync.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ func (zync *Zync) DeploymentConfig() *appsv1.DeploymentConfig {
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: "zync",
Name: ZyncSecretName,
},
Key: "DATABASE_URL",
Key: ZyncSecretDatabaseURLFieldName,
},
},
},
Expand Down
68 changes: 47 additions & 21 deletions pkg/3scale/amp/operator/ampimages_reconciler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package operator

import (
"fmt"

"github.com/3scale/3scale-operator/pkg/3scale/amp/component"
imagev1 "github.com/openshift/api/image/v1"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -75,48 +77,72 @@ func (r *AMPImagesReconciler) ampImages() (*component.AmpImages, error) {
return component.NewAmpImages(opts), nil
}

func (r *AMPImagesReconciler) reconcileImageStream(desiredImageStream *imagev1.ImageStream) error {
err := r.InitializeAsAPIManagerObject(desiredImageStream)
func (r *AMPImagesReconciler) reconcileBackendImageStream(desiredImageStream *imagev1.ImageStream) error {
reconciler := NewImageStreamBaseReconciler(r.BaseAPIManagerLogicReconciler, NewImageStreamGenericReconciler())
err := reconciler.Reconcile(desiredImageStream)
if err != nil {
return err
}

return r.imagestreamReconciler.Reconcile(desiredImageStream)
r.Logger().Info(fmt.Sprintf("%s reconciled", ObjectInfo(desiredImageStream)))
return nil
}

func (r *AMPImagesReconciler) reconcileServiceAccount(desiredServiceAccount *v1.ServiceAccount) error {
err := r.InitializeAsAPIManagerObject(desiredServiceAccount)
func (r *AMPImagesReconciler) reconcileZyncImageStream(desiredImageStream *imagev1.ImageStream) error {
reconciler := NewImageStreamBaseReconciler(r.BaseAPIManagerLogicReconciler, NewImageStreamGenericReconciler())
err := reconciler.Reconcile(desiredImageStream)
if err != nil {
return err
}

return r.serviceAccountReconciler.Reconcile(desiredServiceAccount)
}

func (r *AMPImagesReconciler) reconcileBackendImageStream(desiredImageStream *imagev1.ImageStream) error {
return r.reconcileImageStream(desiredImageStream)
}

func (r *AMPImagesReconciler) reconcileZyncImageStream(desiredImageStream *imagev1.ImageStream) error {
return r.reconcileImageStream(desiredImageStream)
r.Logger().Info(fmt.Sprintf("%s reconciled", ObjectInfo(desiredImageStream)))
return nil
}

func (r *AMPImagesReconciler) reconcileApicastImageStream(desiredImageStream *imagev1.ImageStream) error {
return r.reconcileImageStream(desiredImageStream)
reconciler := NewImageStreamBaseReconciler(r.BaseAPIManagerLogicReconciler, NewImageStreamGenericReconciler())
err := reconciler.Reconcile(desiredImageStream)
if err != nil {
return err
}
r.Logger().Info("apicast imagestream reconciled")
return nil
}

func (r *AMPImagesReconciler) reconcileSystemImageStream(desiredImageStream *imagev1.ImageStream) error {
return r.reconcileImageStream(desiredImageStream)
reconciler := NewImageStreamBaseReconciler(r.BaseAPIManagerLogicReconciler, NewImageStreamGenericReconciler())
err := reconciler.Reconcile(desiredImageStream)
if err != nil {
return err
}
r.Logger().Info(fmt.Sprintf("%s reconciled", ObjectInfo(desiredImageStream)))
return nil
}

func (r *AMPImagesReconciler) reconcileZyncDatabasePostgreSQLImageStream(desiredImageStream *imagev1.ImageStream) error {
return r.reconcileImageStream(desiredImageStream)
reconciler := NewImageStreamBaseReconciler(r.BaseAPIManagerLogicReconciler, NewImageStreamGenericReconciler())
err := reconciler.Reconcile(desiredImageStream)
if err != nil {
return err
}
r.Logger().Info(fmt.Sprintf("%s reconciled", ObjectInfo(desiredImageStream)))
return nil
}

func (r *AMPImagesReconciler) reconcileSystemMemcachedImageStream(desiredImageStream *imagev1.ImageStream) error {
return r.reconcileImageStream(desiredImageStream)
reconciler := NewImageStreamBaseReconciler(r.BaseAPIManagerLogicReconciler, NewImageStreamGenericReconciler())
err := reconciler.Reconcile(desiredImageStream)
if err != nil {
return err
}
r.Logger().Info(fmt.Sprintf("%s reconciled", ObjectInfo(desiredImageStream)))
return nil
}

func (r *AMPImagesReconciler) reconcileDeploymentsServiceAccount(desiredServiceAccount *v1.ServiceAccount) error {
return r.reconcileServiceAccount(desiredServiceAccount)
reconciler := NewServiceAccountBaseReconciler(r.BaseAPIManagerLogicReconciler, NewCreateOnlyServiceAccountReconciler())
err := reconciler.Reconcile(desiredServiceAccount)
if err != nil {
return err
}
r.Logger().Info(fmt.Sprintf("%s reconciled", ObjectInfo(desiredServiceAccount)))
return nil
}
Loading

0 comments on commit 8049224

Please sign in to comment.