Skip to content

Commit

Permalink
feat: Ability to set APICAST_SERVICE_CACHE_SIZE
Browse files Browse the repository at this point in the history
Add optional fields in the Apicast production and staging sections of
the APIManager CRD that set the `APICAST_SERVICE_CACHE_SIZE` environment
variable in the Apicast containers
  • Loading branch information
sergioifg94 committed Nov 10, 2022
1 parent 5c915e6 commit 3ad3b0d
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apis/apps/v1alpha1/apimanager_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ type ApicastProductionSpec struct {
// * character, which matches all hosts, effectively disables the proxy.
// +optional
NoProxy *string `json:"noProxy,omitempty"` // NO_PROXY
// ServiceCacheSize specifies the number of services that APICast can store in the internal cache
// +optional
ServiceCacheSize *int32 `json:"serviceCacheSize,omitempty"`
}

type ApicastStagingSpec struct {
Expand Down Expand Up @@ -315,6 +318,9 @@ type ApicastStagingSpec struct {
// * character, which matches all hosts, effectively disables the proxy.
// +optional
NoProxy *string `json:"noProxy,omitempty"` // NO_PROXY
// ServiceCacheSize specifies the number of services that APICast can store in the internal cache
// +optional
ServiceCacheSize *int32 `json:"serviceCacheSize,omitempty"`
}

type BackendSpec struct {
Expand Down
10 changes: 10 additions & 0 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions config/crd/bases/apps.3scale.net_apimanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,11 @@ spec:
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
serviceCacheSize:
description: ServiceCacheSize specifies the number of services
that APICast can store in the internal cache
format: int32
type: integer
tolerations:
items:
description: The pod this Toleration is attached to tolerates
Expand Down Expand Up @@ -2243,6 +2248,11 @@ spec:
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
serviceCacheSize:
description: ServiceCacheSize specifies the number of services
that APICast can store in the internal cache
format: int32
type: integer
tolerations:
items:
description: The pod this Toleration is attached to tolerates
Expand Down
8 changes: 8 additions & 0 deletions pkg/3scale/amp/component/apicast.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ func (apicast *Apicast) buildApicastStagingEnv() []v1.EnvVar {
result = append(result, helper.EnvVarFromValue("NO_PROXY", *apicast.Options.StagingNoProxy))
}

if apicast.Options.StagingServiceCacheSize != nil {
result = append(result, helper.EnvVarFromValue("APICAST_SERVICE_CACHE_SIZE", fmt.Sprintf("%d", *apicast.Options.StagingServiceCacheSize)))
}

return result
}

Expand Down Expand Up @@ -437,6 +441,10 @@ func (apicast *Apicast) buildApicastProductionEnv() []v1.EnvVar {
result = append(result, helper.EnvVarFromValue("NO_PROXY", *apicast.Options.ProductionNoProxy))
}

if apicast.Options.ProductionServiceCacheSize != nil {
result = append(result, helper.EnvVarFromValue("APICAST_SERVICE_CACHE_SIZE", fmt.Sprintf("%d", *apicast.Options.ProductionServiceCacheSize)))
}

return result
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/3scale/amp/component/apicast_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ type ApicastOptions struct {
StagingHTTPSProxy *string
StagingNoProxy *string

ProductionServiceCacheSize *int32
StagingServiceCacheSize *int32

AdditionalPodAnnotations map[string]string `validate:"required"`
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/3scale/amp/operator/apicast_options_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func (a *ApicastOptionsProvider) GetApicastOptions() (*component.ApicastOptions,
a.apicastOptions.StagingHTTPSCertificateSecretName = &a.apimanager.Spec.Apicast.StagingSpec.HTTPSCertificateSecretRef.Name
}

a.apicastOptions.ProductionServiceCacheSize = a.apimanager.Spec.Apicast.ProductionSpec.ServiceCacheSize
a.apicastOptions.StagingServiceCacheSize = a.apimanager.Spec.Apicast.StagingSpec.ServiceCacheSize

a.setResourceRequirementsOptions()
a.setNodeAffinityAndTolerationsOptions()
a.setReplicas()
Expand Down
23 changes: 23 additions & 0 deletions pkg/3scale/amp/operator/apicast_options_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,29 @@ func TestGetApicastOptionsProvider(t *testing.T) {
return opts
},
},
{"WithServiceCacheSize",
func() *appsv1alpha1.APIManager {
apimanager := basicApimanagerTestApicastOptions()
var stagingCacheSize int32 = 10
var productionCacheSize int32 = 20

apimanager.Spec.Apicast.ProductionSpec.ServiceCacheSize = &productionCacheSize
apimanager.Spec.Apicast.StagingSpec.ServiceCacheSize = &stagingCacheSize

return apimanager
},
func() *component.ApicastOptions {
opts := defaultApicastOptions()

var stagingCacheSize int32 = 10
var productionCacheSize int32 = 20

opts.ProductionServiceCacheSize = &productionCacheSize
opts.StagingServiceCacheSize = &stagingCacheSize

return opts
},
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 3ad3b0d

Please sign in to comment.