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

Commit

Permalink
Add support for the instance bootstrap method in BOSH links
Browse files Browse the repository at this point in the history
- Add new bootstrap field of the type boolean into JobInstance struct
- Add unit tests for ensuring generated job instances have the proper information
- Only set bootstrap to TRUE, if the instance is the one with index 0
- Extend the redis bosh release asset, to support the rendering of
  `redis.conf.erb`, where #596
  was originated.
  • Loading branch information
qu1queee authored and Vlad Iovanov committed Oct 1, 2019
1 parent 0127e56 commit c388b70
Show file tree
Hide file tree
Showing 10 changed files with 798 additions and 39 deletions.
2 changes: 1 addition & 1 deletion pkg/bosh/manifest/cmd_instance_group_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (dg *InstanceGroupResolver) renderJobBPM(currentJob *Job, baseDir string) e
&btg.InstanceInfo{
Address: jobInstance.Address,
AZ: jobInstance.AZ,
Bootstrap: jobInstance.Index == 0,
Bootstrap: jobInstance.Bootstrap,
Index: jobInstance.Index,
Deployment: dg.manifest.Name,
Name: jobInstance.Name,
Expand Down
8 changes: 4 additions & 4 deletions pkg/bosh/manifest/cmd_instance_group_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ var _ = Describe("InstanceGroupResolver", func() {
jobInstancesRedis := manifest.InstanceGroups[0].Jobs[0].Properties.Quarks.Instances

compareToFakeRedis := []JobInstance{
{Address: "foo-deployment-redis-slave-0", AZ: "z1", Index: 0, Instance: 0, Name: "redis-slave-redis-server"},
{Address: "foo-deployment-redis-slave-1", AZ: "z2", Index: 1, Instance: 0, Name: "redis-slave-redis-server"},
{Address: "foo-deployment-redis-slave-2", AZ: "z1", Index: 2, Instance: 1, Name: "redis-slave-redis-server"},
{Address: "foo-deployment-redis-slave-3", AZ: "z2", Index: 3, Instance: 1, Name: "redis-slave-redis-server"},
{Address: "foo-deployment-redis-slave-0", AZ: "z1", Index: 0, Instance: 0, Name: "redis-slave-redis-server", Bootstrap: true},
{Address: "foo-deployment-redis-slave-1", AZ: "z2", Index: 1, Instance: 0, Name: "redis-slave-redis-server", Bootstrap: false},
{Address: "foo-deployment-redis-slave-2", AZ: "z1", Index: 2, Instance: 1, Name: "redis-slave-redis-server", Bootstrap: false},
{Address: "foo-deployment-redis-slave-3", AZ: "z2", Index: 3, Instance: 1, Name: "redis-slave-redis-server", Bootstrap: false},
}
Expect(jobInstancesRedis).To(BeEquivalentTo(compareToFakeRedis))
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/bosh/manifest/cmd_render_job_tmpls.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func RenderJobTemplates(
&btg.InstanceInfo{
Address: currentJobInstance.Address,
AZ: currentJobInstance.AZ,
Bootstrap: currentJobInstance.Index == 0,
Bootstrap: currentJobInstance.Bootstrap,
ID: podName,
Index: currentJobInstance.Index,
IP: podIP.String(),
Expand Down
34 changes: 34 additions & 0 deletions pkg/bosh/manifest/cmd_render_job_tmpls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,38 @@ var _ = Describe("Trender", func() {
Expect(string(content)).To(ContainSubstring("maximum_size3: 1000001size"))
})
})

Context("with an instance index if one", func() {
BeforeEach(func() {
deploymentManifest = "../../../testing/assets/ig-resolved.redis.yml"
jobsDir = "../../../testing/assets"
instanceGroupName = "redis-slave"

// By using index 1, we can make sure that an evaluation of spec.bootstrap
// will return false. See https://bosh.io/docs/jobs/#properties-spec for
// more information.
index = 1
podName = "redis-pod-name"
podIP = net.ParseIP("172.17.0.13")
})

AfterEach(func() {
err := os.RemoveAll(filepath.Join(jobsDir, "redis-server"))
Expect(err).NotTo(HaveOccurred())
})

It("renders the configuration erb file correctly", func() {
err := manifest.RenderJobTemplates(deploymentManifest, jobsDir, jobsDir, instanceGroupName, index, podName, podIP)
Expect(err).ToNot(HaveOccurred())

configFile := filepath.Join(jobsDir, "redis-server", "config/redis.conf")
Expect(configFile).Should(BeAnExistingFile())

content, err := ioutil.ReadFile(configFile)

Expect(err).ToNot(HaveOccurred())
Expect(string(content)).To(ContainSubstring("slaveof foo-deployment-redis-slave-0 637"))

})
})
})
13 changes: 7 additions & 6 deletions pkg/bosh/manifest/containerization.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ type Port struct {

// JobInstance for data gathering.
type JobInstance struct {
Address string `json:"address"`
AZ string `json:"az"`
Index int `json:"index"`
Instance int `json:"instance"`
Name string `json:"name"`
Network map[string]interface{} `json:"networks"`
Address string `json:"address"`
AZ string `json:"az"`
Index int `json:"index"`
Instance int `json:"instance"`
Name string `json:"name"`
Bootstrap bool `json:"bootstrap"`
Network map[string]interface{} `json:"networks"`
}

// JobLink describes links inside a job properties quarks.
Expand Down
11 changes: 6 additions & 5 deletions pkg/bosh/manifest/instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ func (ig *InstanceGroup) jobInstances(
name := fmt.Sprintf("%s-%s", ig.NameSanitized(), jobName)

jobsInstances = append(jobsInstances, JobInstance{
Address: address,
AZ: az,
Index: index,
Instance: i,
Name: name,
Address: address,
AZ: az,
Bootstrap: index == 0,
Index: index,
Instance: i,
Name: name,
})
}
}
Expand Down
40 changes: 20 additions & 20 deletions testing/assets/gatherManifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: true
networks: {}
ip: ""
- address: doppler-1-doppler.default.svc.cluster.local
Expand Down Expand Up @@ -95,7 +95,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: doppler-2-doppler.default.svc.cluster.local
Expand Down Expand Up @@ -123,7 +123,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: doppler-3-doppler.default.svc.cluster.local
Expand Down Expand Up @@ -151,7 +151,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: doppler-4-doppler.default.svc.cluster.local
Expand Down Expand Up @@ -179,7 +179,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: doppler-5-doppler.default.svc.cluster.local
Expand Down Expand Up @@ -207,7 +207,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: doppler-6-doppler.default.svc.cluster.local
Expand Down Expand Up @@ -235,7 +235,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: doppler-7-doppler.default.svc.cluster.local
Expand All @@ -246,7 +246,7 @@ instance_groups:
name: doppler-doppler
bpm: null
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
release: loggregator
Expand Down Expand Up @@ -343,7 +343,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: true
networks: {}
ip: ""
- address: doppler-1-doppler.default.svc.cluster.local
Expand Down Expand Up @@ -371,7 +371,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: doppler-2-doppler.default.svc.cluster.local
Expand Down Expand Up @@ -399,7 +399,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: doppler-3-doppler.default.svc.cluster.local
Expand Down Expand Up @@ -427,7 +427,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: doppler-4-doppler.default.svc.cluster.local
Expand Down Expand Up @@ -455,7 +455,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: doppler-5-doppler.default.svc.cluster.local
Expand Down Expand Up @@ -483,7 +483,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: doppler-6-doppler.default.svc.cluster.local
Expand Down Expand Up @@ -511,7 +511,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: doppler-7-doppler.default.svc.cluster.local
Expand All @@ -522,7 +522,7 @@ instance_groups:
name: doppler-doppler
bpm: null
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
properties:
Expand Down Expand Up @@ -567,7 +567,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: true
networks: {}
ip: ""
- address: log-api-1-loggregator_trafficcontroller.default.svc.cluster.local
Expand Down Expand Up @@ -607,7 +607,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: log-api-2-loggregator_trafficcontroller.default.svc.cluster.local
Expand Down Expand Up @@ -647,7 +647,7 @@ instance_groups:
limits:
open_files: 65536
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
- address: log-api-3-loggregator_trafficcontroller.default.svc.cluster.local
Expand All @@ -658,7 +658,7 @@ instance_groups:
name: log-api-loggregator_trafficcontroller
bpm: null
fingerprint: null
bootstrap: 0
bootstrap: false
networks: {}
ip: ""
release: loggregator
Expand Down
81 changes: 81 additions & 0 deletions testing/assets/ig-resolved.redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: redis-deployment
director_uuid: ""
instance_groups:
- name: redis-slave
instances: 1
azs: [z1, z2]
jobs:
- name: redis-server
release: redis
properties:
quarks:
consumes:
redis:
instances:
- address: foo-deployment-redis-slave-0
az: z1
bootstrap: true
index: 0
instance: 0
name: redis-slave-redis-server
networks: null
- address: foo-deployment-redis-slave-1
az: z2
bootstrap: false
index: 1
instance: 0
name: redis-slave-redis-server
networks: null
properties:
base_dir: /var/vcap/store/redis
password: null
port: 6379
instances:
- address: foo-deployment-redis-slave-0
az: z1
bootstrap: true
index: 0
instance: 0
name: redis-slave-redis-server
networks: null
- address: foo-deployment-redis-slave-1
az: z2
bootstrap: false
index: 1
instance: 0
name: redis-slave-redis-server
networks: null
bpm:
processes:
- args:
- /var/vcap/jobs/redis/config/redis.conf
ephemeral_disk: true
executable: /var/vcap/packages/redis-4/bin/redis-server
hooks:
pre_start: /var/vcap/jobs/redis/bin/pre_start.sh
limits:
open_files: 12500
name: redis
persistent_disk: true
unsafe: {}
unsupported_template: false
debug: false
envs: null
replication: true
is_addon: false
ports: null
post_start: {}
pre_render_scripts:
bpm: null
ig_resolver: null
jobs: null
release: ""
run:
healthcheck: null
security_context: null
networks:
- name: default
persistent_disk_type: medium
stemcell: default
vm_resources: null
vm_type: medium
2 changes: 0 additions & 2 deletions testing/assets/jobs-src/redis/redis-server/job.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ packages: [redis-4]
templates:
bpm.yml.erb: config/bpm.yml
redis.conf.erb: config/redis.conf
health_check: bin/health_check
pre_start.sh: bin/pre_start.sh

provides:
- name: redis
Expand Down
Loading

0 comments on commit c388b70

Please sign in to comment.