Skip to content

Commit

Permalink
Adds cf_Server config for scalingengine
Browse files Browse the repository at this point in the history
  • Loading branch information
bonzofenix committed Nov 12, 2024
1 parent 3c4421a commit 0e5dda8
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 0 deletions.
11 changes: 11 additions & 0 deletions jobs/scalingengine/spec
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ properties:
autoscaler.scalingengine.server_key:
description: "PEM-encoded server key"

autoscaler.cf_server.port:
description: "the listening port of cf xfcc endpoint"
default: 8080

autoscaler.cf_server.xfcc.valid_org_guid:
description: approve org guid for xfcc endpoint
default: ''

autoscaler.cf_server.xfcc.valid_space_guid:
description: approve space guid for xfcc endpoint
default: ''

autoscaler.scalingengine.health.port:
description: "the listening port of health endpoint"
Expand Down
5 changes: 5 additions & 0 deletions jobs/scalingengine/templates/scalingengine.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ cf:
idle_connection_timeout_ms: <%= p("autoscaler.cf.idle_connection_timeout_ms") %>
max_idle_conns_per_host_ms: <%= p("autoscaler.cf.max_idle_conns_per_host_ms") %>

cf_server:
port: <%= p("autoscaler.cf_server.port") %>
xfcc:
valid_org_guid: <%= p("autoscaler.cf_server.xfcc.valid_org_guid") %>
valid_space_guid: <%= p("autoscaler.cf_server.xfcc.valid_space_guid") %>

server:
port: <%= p("autoscaler.scalingengine.server.port") %>
Expand Down
17 changes: 17 additions & 0 deletions spec/jobs/scalingengine/scalingengine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@
end
end

context "cf server" do
it "includes default port for cf server" do
expect(rendered_template["cf_server"]["port"]).to eq(8080)
end

it "defaults xfcc valid org and space " do
properties["autoscaler"]["cf_server"] = {}
properties["autoscaler"]["cf_server"]["xfcc"] = {
"valid_org_guid" => "some-valid-org-guid",
"valid_space_guid" => "some-valid-space-guid"
}

expect(rendered_template["cf_server"]["xfcc"]["valid_org_guid"]).to eq(properties["autoscaler"]["cf_server"]["xfcc"]["valid_org_guid"])
expect(rendered_template["cf_server"]["xfcc"]["valid_space_guid"]).to eq(properties["autoscaler"]["cf_server"]["xfcc"]["valid_space_guid"])
end
end

context "uses tls" do
context "policy_db" do
it "includes the ca, cert and key in url when configured" do
Expand Down
1 change: 1 addition & 0 deletions src/autoscaler/helpers/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
type ServerConfig struct {
Port int `yaml:"port"`
TLS models.TLSCerts `yaml:"tls"`
XFCC models.XFCCAuth `yaml:"xfcc"`
}

func NewHTTPServer(logger lager.Logger, conf ServerConfig, handler http.Handler) (ifrit.Runner, error) {
Expand Down
5 changes: 5 additions & 0 deletions src/autoscaler/models/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const (
X509Certificate = "x509"
)

type XFCCAuth struct {
ValidOrgGuid string `yaml:"valid_org_guid"`
ValidSpaceGuid string `yaml:"valid_space_guid"`
}

type BrokerContext struct {
OrgGUID string `json:"organization_guid"`
SpaceGUID string `json:"space_guid"`
Expand Down
6 changes: 6 additions & 0 deletions src/autoscaler/scalingengine/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var defaultHealthConfig = helpers.HealthConfig{
},
}

var defaultCfServerConfig = helpers.ServerConfig{
Port: 8082,
}

var defaultLoggingConfig = helpers.LoggingConfig{
Level: "info",
}
Expand All @@ -49,6 +53,7 @@ type Config struct {
CF cf.Config `yaml:"cf"`
Logging helpers.LoggingConfig `yaml:"logging"`
Server helpers.ServerConfig `yaml:"server"`
CfServer helpers.ServerConfig `yaml:"cf_server"`
Health helpers.HealthConfig `yaml:"health"`
DB DBConfig `yaml:"db"`
DefaultCoolDownSecs int `yaml:"defaultCoolDownSecs"`
Expand All @@ -61,6 +66,7 @@ func LoadConfig(reader io.Reader) (*Config, error) {
CF: defaultCFConfig,
Logging: defaultLoggingConfig,
Server: defaultServerConfig,
CfServer: defaultCfServerConfig,
Health: defaultHealthConfig,
HttpClientTimeout: DefaultHttpClientTimeout,
}
Expand Down
4 changes: 4 additions & 0 deletions src/autoscaler/scalingengine/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ var _ = Describe("Config", func() {
Expect(conf.Server.TLS.CertFile).To(Equal("/var/vcap/jobs/autoscaler/config/certs/server.crt"))
Expect(conf.Server.TLS.CACertFile).To(Equal("/var/vcap/jobs/autoscaler/config/certs/ca.crt"))

Expect(conf.CfServer.Port).To(Equal(2222))
Expect(conf.CfServer.XFCC.ValidOrgGuid).To(Equal("valid_org_guid"))
Expect(conf.CfServer.XFCC.ValidSpaceGuid).To(Equal("valid_space_guid"))

Expect(conf.Health.ServerConfig.Port).To(Equal(9999))
Expect(conf.Logging.Level).To(Equal("debug"))

Expand Down
7 changes: 7 additions & 0 deletions src/autoscaler/scalingengine/config/testdata/valid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ server:
key_file: /var/vcap/jobs/autoscaler/config/certs/server.key
cert_file: /var/vcap/jobs/autoscaler/config/certs/server.crt
ca_file: /var/vcap/jobs/autoscaler/config/certs/ca.crt

cf_server:
port: 2222
xfcc:
valid_org_guid: valid_org_guid
valid_space_guid: valid_space_guid

health:
server_config:
port: 9999
Expand Down

0 comments on commit 0e5dda8

Please sign in to comment.