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

Change to use AZ name instead of index and support spliters for max-i… #1328

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/go-logr/logr v0.3.0
github.com/go-test/deep v1.0.7
github.com/gonvenience/bunt v1.1.4
github.com/google/uuid v1.2.0 // indirect
github.com/hpcloud/tail v1.0.0
github.com/imdario/mergo v0.3.11
github.com/mattn/go-isatty v0.0.11 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
Expand Down
8 changes: 6 additions & 2 deletions pkg/bosh/bpmconverter/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,14 @@ func (kc *BPMConverter) service(namespace string, deploymentName string, instanc
isActivePassiveModel := bpmConfigs.IsActivePassiveModel()

if len(instanceGroup.AZs) > 0 {
for azIndex := range instanceGroup.AZs {
for azIndex, azName := range instanceGroup.AZs {
services = kc.generateServices(
services,
namespace,
deploymentName,
*instanceGroup,
azIndex,
azName,
isActivePassiveModel,
ports)
}
Expand All @@ -285,6 +286,7 @@ func (kc *BPMConverter) service(namespace string, deploymentName string, instanc
deploymentName,
*instanceGroup,
-1,
"",
isActivePassiveModel,
ports)
}
Expand Down Expand Up @@ -440,6 +442,7 @@ func (kc *BPMConverter) generateServices(
deploymentName string,
instanceGroup bdm.InstanceGroup,
azIndex int,
azName string,
activePassiveModel bool,
ports []corev1.ServicePort) []corev1.Service {
serviceLabels := func(azIndex, ordinal int, includeActiveSelector bool) map[string]string {
Expand All @@ -450,6 +453,7 @@ func (kc *BPMConverter) generateServices(
bdv1.LabelDeploymentName: deploymentName,
bdv1.LabelInstanceGroupName: instanceGroup.Name,
qstsv1a1.LabelAZIndex: strconv.Itoa(azIndex),
qstsv1a1.LabelAZName: azName,
qstsv1a1.LabelPodOrdinal: strconv.Itoa(ordinal),
}
if includeActiveSelector {
Expand All @@ -461,7 +465,7 @@ func (kc *BPMConverter) generateServices(
for i := 0; i < instanceGroup.Instances; i++ {
services = append(services, corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: instanceGroup.IndexedServiceName(i, azIndex),
Name: instanceGroup.IndexedServiceName(i, azIndex, azName),
Namespace: namespace,
Labels: serviceLabels(azIndex, i, false),
},
Expand Down
13 changes: 9 additions & 4 deletions pkg/bosh/bpmconverter/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ var _ = Describe("BPM Converter", func() {
bdv1.LabelDeploymentName: deploymentName,
bdv1.LabelInstanceGroupName: stS.Name,
qstsv1a1.LabelAZIndex: "0",
qstsv1a1.LabelAZName: "z1",
qstsv1a1.LabelPodOrdinal: "0",
qstsv1a1.LabelActivePod: "active",
}))
Expand Down Expand Up @@ -266,11 +267,12 @@ var _ = Describe("BPM Converter", func() {

// Test services for the quarks statefulSet
service0 := resources.Services[0]
Expect(service0.Name).To(Equal(fmt.Sprintf("%s-z%d-0", stS.Name, 0)))
Expect(service0.Name).To(Equal(fmt.Sprintf("%s-%s-0-0", stS.Name, m.InstanceGroups[1].AZs[0])))
Expect(service0.Spec.Selector).To(Equal(map[string]string{
bdv1.LabelDeploymentName: deploymentName,
bdv1.LabelInstanceGroupName: stS.Name,
qstsv1a1.LabelAZIndex: "0",
qstsv1a1.LabelAZName: "z1",
qstsv1a1.LabelPodOrdinal: "0",
}))
Expect(service0.Spec.Ports).To(Equal([]corev1.ServicePort{
Expand All @@ -282,11 +284,12 @@ var _ = Describe("BPM Converter", func() {
}))

service1 := resources.Services[1]
Expect(service1.Name).To(Equal(fmt.Sprintf("%s-z%d-1", stS.Name, 0)))
Expect(service1.Name).To(Equal(fmt.Sprintf("%s-%s-0-1", stS.Name, m.InstanceGroups[1].AZs[0])))
Expect(service1.Spec.Selector).To(Equal(map[string]string{
bdv1.LabelDeploymentName: deploymentName,
bdv1.LabelInstanceGroupName: stS.Name,
qstsv1a1.LabelAZIndex: "0",
qstsv1a1.LabelAZName: "z1",
qstsv1a1.LabelPodOrdinal: "1",
}))
Expect(service1.Spec.Ports).To(Equal([]corev1.ServicePort{
Expand All @@ -298,11 +301,12 @@ var _ = Describe("BPM Converter", func() {
}))

service2 := resources.Services[2]
Expect(service2.Name).To(Equal(fmt.Sprintf("%s-z%d-0", stS.Name, 1)))
Expect(service2.Name).To(Equal(fmt.Sprintf("%s-%s-1-0", stS.Name, m.InstanceGroups[1].AZs[1])))
Expect(service2.Spec.Selector).To(Equal(map[string]string{
bdv1.LabelDeploymentName: deploymentName,
bdv1.LabelInstanceGroupName: stS.Name,
qstsv1a1.LabelAZIndex: "1",
qstsv1a1.LabelAZName: "z2",
qstsv1a1.LabelPodOrdinal: "0",
}))
Expect(service2.Spec.Ports).To(Equal([]corev1.ServicePort{
Expand All @@ -314,11 +318,12 @@ var _ = Describe("BPM Converter", func() {
}))

service3 := resources.Services[3]
Expect(service3.Name).To(Equal(fmt.Sprintf("%s-z%d-1", stS.Name, 1)))
Expect(service3.Name).To(Equal(fmt.Sprintf("%s-%s-1-1", stS.Name, m.InstanceGroups[1].AZs[1])))
Expect(service3.Spec.Selector).To(Equal(map[string]string{
bdv1.LabelDeploymentName: deploymentName,
bdv1.LabelInstanceGroupName: stS.Name,
qstsv1a1.LabelAZIndex: "1",
qstsv1a1.LabelAZName: "z2",
qstsv1a1.LabelPodOrdinal: "1",
}))
Expect(service3.Spec.Ports).To(Equal([]corev1.ServicePort{
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 @@ -134,8 +134,8 @@ var _ = Describe("InstanceGroupResolver", func() {
Expect(bpm.Processes[0].Env["FOOBARWITHLINKVALUES"]).To(Equal("10001"))
Expect(bpm.Processes[0].Env["FOOBARWITHLINKNESTEDVALUES"]).To(Equal("7765"))
Expect(bpm.Processes[0].Env["FOOBARWITHLINKINSTANCESAZ"]).To(Equal("z1"))
Expect(bpm.Processes[0].Env["FOOBARWITHLINKINSTANCESADDRESS"]).To(Equal("doppler-z0-0"))
Expect(bpm.Processes[0].Env["FOOBARWITHSPECADDRESS"]).To(Equal("log-api-z0-0"))
Expect(bpm.Processes[0].Env["FOOBARWITHLINKINSTANCESADDRESS"]).To(Equal("doppler-z1-0-0"))
Expect(bpm.Processes[0].Env["FOOBARWITHSPECADDRESS"]).To(Equal("log-api-z1-0-0"))
Expect(bpm.Processes[0].Env["FOOBARWITHSPECDEPLOYMENT"]).To(Equal("cf"))

// The following block of assertions are related to the usage of
Expand All @@ -147,11 +147,11 @@ var _ = Describe("InstanceGroupResolver", func() {
// We do not support different indexes in BPM data.
Expect(bpm.Processes[0].Env["FOOBARWITHSPECAZ"]).To(Equal("z1"))
Expect(bpm.Processes[0].Env["FOOBARWITHSPECBOOTSTRAP"]).To(Equal("true"))
Expect(bpm.Processes[0].Env["FOOBARWITHSPECID"]).To(Equal("log-api-z0-0"))
Expect(bpm.Processes[0].Env["FOOBARWITHSPECID"]).To(Equal("log-api-z1-0-0"))
Expect(bpm.Processes[0].Env["FOOBARWITHSPECINDEX"]).To(Equal("0"))
Expect(bpm.Processes[0].Env["FOOBARWITHSPECNAME"]).To(Equal("log-api-loggregator_trafficcontroller"))
Expect(bpm.Processes[0].Env["FOOBARWITHSPECNETWORKS"]).To(Equal(""))
Expect(bpm.Processes[0].Env["FOOBARWITHSPECADDRESS"]).To(Equal("log-api-z0-0"))
Expect(bpm.Processes[0].Env["FOOBARWITHSPECADDRESS"]).To(Equal("log-api-z1-0-0"))

Expect(bpm.Ports).To(ContainElement(bpmConfig.Port{
Name: "outgoing_dropsonde_port",
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 @@ -126,7 +126,7 @@ func RenderJobTemplates(
}

// Find job instance that's being rendered
currentJobInstance := job.Properties.Quarks.jobInstance(ig.AZs, specIndex)
currentJobInstance := job.Properties.Quarks.jobInstance(ig.AZs, azIndex, specIndex)
if currentJobInstance == nil {
return errors.Errorf("no job instance found for spec index '%d'", specIndex)
}
Expand Down
61 changes: 47 additions & 14 deletions pkg/bosh/manifest/cmd_render_job_tmpls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ var _ = Describe("RenderJobTemplates", func() {
// will use the instance at the index provided to the RenderJobTemplates func().
Expect(values.Env["FOOBARWITHSPECAZ"]).To(Equal("z1"))
Expect(values.Env["FOOBARWITHSPECBOOTSTRAP"]).To(Equal("true"))
Expect(values.Env["FOOBARWITHSPECID"]).To(Equal("log-api-z0-0"))
Expect(values.Env["FOOBARWITHSPECID"]).To(Equal("log-api-z1-0-0"))
Expect(values.Env["FOOBARWITHSPECINDEX"]).To(Equal("0"))
Expect(values.Env["FOOBARWITHSPECNAME"]).To(Equal("log-api-loggregator_trafficcontroller"))
Expect(values.Env["FOOBARWITHSPECNETWORKS"]).To(Equal(""))
Expect(values.Env["FOOBARWITHSPECADDRESS"]).To(Equal("log-api-z0-0"))
Expect(values.Env["FOOBARWITHSPECADDRESS"]).To(Equal("log-api-z1-0-0"))
Expect(values.Env["FOOBARWITHSPECDEPLOYMENT"]).To(Equal(""))
Expect(values.Env["FOOBARWITHSPECIP"]).To(Equal("172.17.0.13"))
})
Expand Down Expand Up @@ -217,16 +217,16 @@ var _ = Describe("RenderJobTemplates", func() {
It("renders the job erb files correctly", func() {
tests := cases{
// two az
{0, 0, 1, true, "log-api-z0-0", "z1", "0", "true"},
{1, 1, 1, true, "log-api-z0-1", "z1", "1", "false"},
{0, 0, 2, true, "log-api-z1-0", "z2", "2", "false"},
{1, 1, 2, true, "log-api-z1-1", "z2", "3", "false"},
{0, 0, 1, true, "log-api-z1-0-0", "z1", "0", "true"},
{1, 1, 1, true, "log-api-z1-0-1", "z1", "1", "false"},
{0, 0, 2, true, "log-api-z2-1-0", "z2", "2", "false"},
{1, 1, 2, true, "log-api-z2-1-1", "z2", "3", "false"},

// // two az, updated
{0, 1, 1, false, "log-api-z0-0", "z1", "0", "false"},
{1, 0, 1, false, "log-api-z0-1", "z1", "1", "false"}, // TODO would have expected this to be bootstrap
{0, 1, 2, false, "log-api-z1-0", "z2", "2", "false"},
{1, 0, 2, false, "log-api-z1-1", "z2", "3", "true"},
{0, 1, 1, false, "log-api-z1-0-0", "z1", "0", "false"},
{1, 0, 1, false, "log-api-z1-0-1", "z1", "1", "false"}, // TODO would have expected this to be bootstrap
{0, 1, 2, false, "log-api-z2-1-0", "z2", "2", "false"},
{1, 0, 2, false, "log-api-z2-1-1", "z2", "3", "true"},

// TODO two az, happily generates out of bounds - nothing we can do, replicas is automatically increased
// {20, 20, 1, true, "log-api-z0-20", "z1", "20", "false"},
Expand All @@ -248,6 +248,39 @@ var _ = Describe("RenderJobTemplates", func() {
})
})

When("multiple SAME azs are used", func() {
BeforeEach(func() {
deploymentManifest = assetPath + "/templateRenderManifestSameAZ.yml"
})

It("renders the job erb files correctly", func() {
tests := cases{
// two az
{0, 0, 1, true, "log-api-a1-0-0", "a1", "0", "true"},
{1, 1, 1, true, "log-api-a1-0-1", "a1", "1", "false"},
{0, 0, 2, true, "log-api-a1-1-0", "a1", "2", "false"},
{1, 1, 2, true, "log-api-a1-1-1", "a1", "3", "false"},

// // two az, updated
{0, 1, 1, false, "log-api-a1-0-0", "a1", "0", "false"},
{1, 0, 1, false, "log-api-a1-0-1", "a1", "1", "false"}, // TODO would have expected this to be bootstrap
{0, 1, 2, false, "log-api-a1-1-0", "a1", "2", "false"},
{1, 0, 2, false, "log-api-a1-1-1", "a1", "3", "true"},
}

for i, t := range tests {
err := manifest.RenderJobTemplates(deploymentManifest, assetPath, tmpDir, instanceGroupName, podIP, t.azIndex, t.podOrdinal, replicas, t.initial)
Expect(err).ToNot(HaveOccurred())
values := readBPM(filepath.Join(tmpDir, "loggregator_trafficcontroller", "config/spec.yml"))
errstr := fmt.Sprintf("test case %d", i+1)
Expect(values.Env["SPEC_ADDRESS"]).To(Equal(t.beAddress), errstr)
Expect(values.Env["SPEC_AZ"]).To(Equal(t.beAZ), errstr)
Expect(values.Env["SPEC_INDEX"]).To(Equal(t.beIndex), errstr)
Expect(values.Env["SPEC_BOOTSTRAP"]).To(Equal(t.beBootstrap), errstr)
}
})
})

When("one azs is used", func() {
BeforeEach(func() {
deploymentManifest = assetPath + "/templateRenderManifestOneAZ.yml"
Expand All @@ -256,12 +289,12 @@ var _ = Describe("RenderJobTemplates", func() {
It("renders the job erb files correctly", func() {
tests := cases{
// single az
{0, 0, 1, true, "log-api-z0-0", "z1", "0", "true"},
{1, 1, 1, true, "log-api-z0-1", "z1", "1", "false"},
{0, 0, 1, true, "log-api-z1-0-0", "z1", "0", "true"},
{1, 1, 1, true, "log-api-z1-0-1", "z1", "1", "false"},

// single az, updated
{0, 1, 1, false, "log-api-z0-0", "z1", "0", "false"},
{1, 0, 1, false, "log-api-z0-1", "z1", "1", "true"},
{0, 1, 1, false, "log-api-z1-0-0", "z1", "0", "false"},
{1, 0, 1, false, "log-api-z1-0-1", "z1", "1", "true"},
}

for i, t := range tests {
Expand Down
12 changes: 6 additions & 6 deletions pkg/bosh/manifest/containerization.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ type JobInstance struct {
Network map[string]interface{} `json:"networks"`
}

func (q Quarks) jobInstance(azs []string, specIndex int) *JobInstance {
func (q Quarks) jobInstance(azs []string, azIndex int, specIndex int) *JobInstance {
for _, instance := range q.Instances {
if len(azs) > 0 {
for i, az := range azs {
if instance.AZ == az {
if names.SpecIndex(i+1, instance.Instance) == specIndex {
return &instance
}
instancesPerZone := len(q.Instances) / len(azs)
zoneStart := (azIndex - 1) * instancesPerZone
if instance.AZ == azs[azIndex-1] && instance.Index >= zoneStart {
if names.SpecIndex(azIndex, instance.Instance) == specIndex {
return &instance
}
}
} else {
Expand Down
10 changes: 5 additions & 5 deletions pkg/bosh/manifest/instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ func (ig *InstanceGroup) IsErrand() bool {

// IndexedServiceName constructs an indexed service name. It's used to construct the service
// names other than the headless service.
func (ig *InstanceGroup) IndexedServiceName(index int, azIndex int) string {
func (ig *InstanceGroup) IndexedServiceName(index int, azIndex int, azName string) string {
sn := boshnames.TruncatedServiceName(ig.Name, 53)
if azIndex > -1 {
return fmt.Sprintf("%s-z%d-%d", sn, azIndex, index)
return fmt.Sprintf("%s-%s-%d-%d", sn, azName, azIndex, index)
}
return fmt.Sprintf("%s-%d", sn, index)
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func (ig *InstanceGroup) jobInstances(
//specIndex := names.SpecIndex(azIndex+1, i))

jobsInstances = append(jobsInstances, JobInstance{
Address: ig.IndexedServiceName(i, -1),
Address: ig.IndexedServiceName(i, -1, ""),
AZ: "",
Bootstrap: i == bootstrapIndex,
Index: i,
Expand Down Expand Up @@ -174,13 +174,13 @@ func (ig *InstanceGroup) jobInstancesAZ(
index := len(jobsInstances)

jobsInstances = append(jobsInstances, JobInstance{
Address: ig.IndexedServiceName(i, azIndex),
Address: ig.IndexedServiceName(i, azIndex, az),
AZ: az,
Bootstrap: index == bootstrapIndex,
Index: index,
Instance: i,
Name: fmt.Sprintf("%s-%s", igName, jobName),
ID: fmt.Sprintf("%s-z%d-%d", igName, azIndex, index%ig.Instances),
ID: fmt.Sprintf("%s-%s-%d-%d", igName, az, azIndex, index%ig.Instances),
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/kube/util/boshdns/bosh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ var _ = Describe("BOSHDomainNameService", func() {

By("checking for entries for diego-cells in mutli-zone")
Expect(corefile).To(ContainSubstring(`
template IN A diego-cell-z0-0.cell.service.cf.internal {
match ^diego-cell-z0-0\.cell\.service\.cf\.internal\.$
answer "{{ .Name }} 60 IN CNAME diego-cell-z0-0.default.svc."
template IN A diego-cell-az1-0-0.cell.service.cf.internal {
match ^diego-cell-az1-0-0\.cell\.service\.cf\.internal\.$
answer "{{ .Name }} 60 IN CNAME diego-cell-az1-0-0.default.svc."
fallthrough`))
})
})
Expand Down
9 changes: 6 additions & 3 deletions pkg/kube/util/boshdns/corefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ func gatherAllRewrites(rewrites []string,
alias Alias) []string {
if target.Query == "_" {
if len(instanceGroup.AZs) > 0 {
for azIndex := range instanceGroup.AZs {
for azIndex, azName := range instanceGroup.AZs {
rewrites = gatherRewritesForInstances(rewrites,
instanceGroup,
target,
namespace,
azIndex,
azName,
alias)
}
} else {
Expand All @@ -145,6 +146,7 @@ func gatherAllRewrites(rewrites []string,
target,
namespace,
-1,
"",
alias)
}
} else {
Expand All @@ -164,16 +166,17 @@ func gatherRewritesForInstances(rewrites []string,
target Target,
namespace string,
azIndex int,
azName string,
alias Alias) []string {
id := ""
for i := 0; i < instanceGroup.Instances; i++ {
if azIndex > -1 {
id = fmt.Sprintf("%s-z%d-%d", target.InstanceGroup, azIndex, i)
id = fmt.Sprintf("%s-%s-%d-%d", target.InstanceGroup, azName, azIndex, i)
} else {
id = fmt.Sprintf("%s-%d", target.InstanceGroup, i)
}
from := strings.Replace(alias.Domain, "_", id, 1)
serviceName := instanceGroup.IndexedServiceName(i, azIndex)
serviceName := instanceGroup.IndexedServiceName(i, azIndex, azName)
to := fmt.Sprintf("%s.%s.svc.%s", serviceName, namespace, clusterDomain)
rewrites = append(rewrites, newTemplate(from, to))
}
Expand Down
Loading