Skip to content
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
28 changes: 5 additions & 23 deletions internal/bootstrap/gcp/datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ func (b *GCPBootstrapper) ensureConfigManagers() {
}
}

// adoptLegacyEnvFields moves state that a caller supplied through the deprecated top-level
// environment fields into the primary data center. Infra files written before multi-DC support
// carry the primary data center's nodes and IPs there.
// adoptLegacyEnvFields moves state that reached the environment through the fields the primary
// data center's state lived in before multi-DC support into the primary data center itself. This
// is the only place those fields are still read: infra files written by an earlier OMS carry the
// nodes and IPs there, and cleanup and restart-vms have to keep working with them.
func (b *GCPBootstrapper) adoptLegacyEnvFields() {
primary := b.Env.DataCenters[0]
if len(primary.ControlPlaneNodes) == 0 {
Expand All @@ -91,7 +92,7 @@ func (b *GCPBootstrapper) adoptLegacyEnvFields() {
}

if primary.SSHProxyIP == "" {
primary.SSHProxyIP = b.Env.SshProxyIP
primary.SSHProxyIP = b.Env.SSHProxyIP
}

if primary.InstallConfig == nil {
Expand All @@ -104,25 +105,6 @@ func (b *GCPBootstrapper) adoptLegacyEnvFields() {
}
}

// mirrorPrimaryDataCenter projects the primary data center's state back onto the top-level
// environment fields it lived in before multi-DC support. The steps that still read those fields
// keep working while they are migrated one by one, and the infra file keeps the shape an earlier
// OMS wrote. The projection is one-way and never read back into a DataCenter.
func (b *GCPBootstrapper) mirrorPrimaryDataCenter() {
if len(b.Env.DataCenters) == 0 {
return
}

primary := b.primaryDC()
b.Env.ControlPlaneNodes = primary.ControlPlaneNodes
b.Env.CephNodes = primary.CephNodes
b.Env.GatewayIP = primary.GatewayIP
b.Env.PublicGatewayIP = primary.PublicGatewayIP
b.Env.SshProxyIP = primary.SSHProxyIP
b.Env.InstallConfig = primary.InstallConfig
b.Env.ExistingConfigUsed = primary.ExistingConfigUsed
}

// newDataCenter builds one data center, deriving its resource names, file paths and domains
// from the environment and the data-center suffix.
func newDataCenter(env *CodesphereEnvironment, id int, suffix string, newICG func() installer.InstallConfigManager) *datacenter.DataCenter {
Expand Down
2 changes: 0 additions & 2 deletions internal/bootstrap/gcp/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ func (b *GCPBootstrapper) EnsureComputeInstances() error {
})
}

b.mirrorPrimaryDataCenter()

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/bootstrap/gcp/gce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,8 @@ var _ = Describe("GCE", func() {

err := bs.EnsureComputeInstances()
Expect(err).NotTo(HaveOccurred())
Expect(len(bs.Env.ControlPlaneNodes)).To(Equal(3))
Expect(len(bs.Env.CephNodes)).To(Equal(3))
Expect(len(bs.Env.DataCenters[0].ControlPlaneNodes)).To(Equal(3))
Expect(len(bs.Env.DataCenters[0].CephNodes)).To(Equal(3))
Expect(bs.Env.PostgreSQLNode).NotTo(BeNil())
Expect(bs.Env.Jumpbox).NotTo(BeNil())
})
Expand Down
19 changes: 9 additions & 10 deletions internal/bootstrap/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ type CodesphereEnvironment struct {
// DNSRecords records the DNS records the bootstrap created, so cleanup deletes exactly
// those instead of recomputing the list.
DNSRecords []DNSRecordName `json:"dns_records,omitempty"`
// ControlPlaneNodes and CephNodes are where the primary data center's nodes lived before
// multi-DC support. The steps that have not been migrated to DataCenters yet still use
// them, and infra files written by an earlier OMS carry the nodes here.
ControlPlaneNodes []*node.Node `json:"control_plane_nodes"`
CephNodes []*node.Node `json:"ceph_nodes"`
// ControlPlaneNodes, CephNodes, GatewayIP, PublicGatewayIP and SSHProxyIP are where the
// primary data center's nodes and addresses lived before multi-DC support. Nothing writes
// them any more; they are only read, by ensureDataCenters, so an infra file written by an
// earlier OMS still yields a usable primary data center.
ControlPlaneNodes []*node.Node `json:"control_plane_nodes,omitempty"`
CephNodes []*node.Node `json:"ceph_nodes,omitempty"`
// ContainerRegistryURL is the resolved registry server all data centers pull images from.
ContainerRegistryURL string `json:"container_registry_url,omitempty"`
RegistryUsername string `json:"-"`
Expand All @@ -215,9 +216,9 @@ type CodesphereEnvironment struct {
SpotVMs bool `json:"spot_vms"`
WriteConfig bool `json:"-"`
RecoverConfig bool `json:"-"`
GatewayIP string `json:"gateway_ip"`
PublicGatewayIP string `json:"public_gateway_ip"`
SshProxyIP string `json:"ssh_proxy_ip"`
GatewayIP string `json:"gateway_ip,omitempty"`
PublicGatewayIP string `json:"public_gateway_ip,omitempty"`
SSHProxyIP string `json:"ssh_proxy_ip,omitempty"`
RegistryType RegistryType `json:"registry_type"`
GitHubPAT string `json:"-"`
GitHubAppName string `json:"-"`
Expand Down Expand Up @@ -943,8 +944,6 @@ func (b *GCPBootstrapper) EnsureGatewayIPAddresses() error {
}
}

b.mirrorPrimaryDataCenter()

return nil
}

Expand Down
19 changes: 11 additions & 8 deletions internal/bootstrap/gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ var _ = Describe("GCP Bootstrapper", func() {
// Verify nodes are properly set in the environment
Expect(bs.Env.Jumpbox).NotTo(BeNil())
Expect(bs.Env.PostgreSQLNode).NotTo(BeNil())
Expect(bs.Env.CephNodes).To(HaveLen(3))
Expect(bs.Env.ControlPlaneNodes).To(HaveLen(3))
primary := bs.Env.DataCenters[0]
Expect(primary.CephNodes).To(HaveLen(3))
Expect(primary.ControlPlaneNodes).To(HaveLen(3))

// Verify mock returns expected values
Expect(bs.Env.Jumpbox.GetName()).To(Equal("jumpbox"))
Expand All @@ -283,19 +284,19 @@ var _ = Describe("GCP Bootstrapper", func() {
Expect(bs.Env.PostgreSQLNode.GetExternalIP()).To(Equal("1.2.3.4"))
Expect(bs.Env.PostgreSQLNode.GetInternalIP()).To(Equal("10.0.0.1"))

for _, cephNode := range bs.Env.CephNodes {
for _, cephNode := range primary.CephNodes {
Expect(cephNode.GetName()).To(MatchRegexp("ceph-\\d+"))
Expect(cephNode.GetExternalIP()).To(Equal("1.2.3.4"))
Expect(cephNode.GetInternalIP()).To(Equal("10.0.0.1"))
}

for _, cpNode := range bs.Env.ControlPlaneNodes {
for _, cpNode := range primary.ControlPlaneNodes {
Expect(cpNode.GetName()).To(MatchRegexp("k0s-\\d+"))
Expect(cpNode.GetExternalIP()).To(Equal("1.2.3.4"))
Expect(cpNode.GetInternalIP()).To(Equal("10.0.0.1"))
}

Expect(len(bs.Env.InstallConfig.Codesphere.ManagedServices)).To(Equal(5))
Expect(len(primary.InstallConfig.Codesphere.ManagedServices)).To(Equal(5))
})
})

Expand Down Expand Up @@ -1142,9 +1143,11 @@ var _ = Describe("GCP Bootstrapper", func() {

err := bs.EnsureGatewayIPAddresses()
Expect(err).NotTo(HaveOccurred())
Expect(bs.Env.GatewayIP).To(Equal("1.1.1.1"))
Expect(bs.Env.PublicGatewayIP).To(Equal("2.2.2.2"))
Expect(bs.Env.SshProxyIP).To(Equal("3.3.3.3"))

primary := bs.Env.DataCenters[0]
Expect(primary.GatewayIP).To(Equal("1.1.1.1"))
Expect(primary.PublicGatewayIP).To(Equal("2.2.2.2"))
Expect(primary.SSHProxyIP).To(Equal("3.3.3.3"))
})
})

Expand Down
1 change: 0 additions & 1 deletion internal/bootstrap/gcp/infrafile.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func (b *GCPBootstrapper) WriteInfraFile() error {

// The steps that still write the top-level node and IP fields are migrated to DataCenters
// one by one, so keep both in sync until the last one is.
b.mirrorPrimaryDataCenter()

envBytes, err := json.MarshalIndent(b.Env, "", " ")
if err != nil {
Expand Down
6 changes: 0 additions & 6 deletions internal/bootstrap/gcp/install_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ func (b *GCPBootstrapper) ensureInstallConfig(dc *datacenter.DataCenter) error {
// A secondary data center without a config of its own is left unset here, so
// seedSecondaryDataCenter can derive it from the primary data center instead of the profile.

b.mirrorPrimaryDataCenter()

return nil
}

Expand Down Expand Up @@ -501,8 +499,6 @@ func (b *GCPBootstrapper) updateInstallConfig(dc *datacenter.DataCenter) error {
return fmt.Errorf("failed to copy secrets file to jumpbox: %w", err)
}

b.mirrorPrimaryDataCenter()

return nil
}

Expand Down Expand Up @@ -780,8 +776,6 @@ func (b *GCPBootstrapper) ensureSecrets(dc *datacenter.DataCenter) error {
if dc.IsPrimary() {
b.Env.Secrets = dc.ConfigManager.GetVault()
}

b.mirrorPrimaryDataCenter()
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/bootstrap/gcp/install_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ var _ = Describe("Installconfig & Secrets", func() {
})
Describe("Valid UpdateInstallConfig", func() {
It("updates config and writes files", func() {
csEnv.SshProxyIP = "3.3.3.3"
csEnv.SSHProxyIP = "3.3.3.3"

icg.EXPECT().GenerateSecrets().Return(nil)
icg.EXPECT().WriteInstallConfig("fake-config-file", true).Return(nil)
Expand Down
13 changes: 0 additions & 13 deletions internal/bootstrap/gcp/multi_dc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,6 @@ var _ = Describe("Multi-DC bootstrap", func() {
Expect(bs.InstallK0s()).To(Succeed())
})

It("mirrors the primary data center onto the legacy infra file fields", func() {
expectBootstrapMocks("test-project-12345")

Expect(bs.Bootstrap()).To(Succeed())

primary := bs.Env.DataCenters[0]
Expect(bs.Env.ControlPlaneNodes).To(Equal(primary.ControlPlaneNodes))
Expect(bs.Env.CephNodes).To(Equal(primary.CephNodes))
Expect(bs.Env.GatewayIP).To(Equal(primary.GatewayIP))
Expect(bs.Env.PublicGatewayIP).To(Equal(primary.PublicGatewayIP))
Expect(bs.Env.SshProxyIP).To(Equal(primary.SSHProxyIP))
})

Describe("validateMultiDC", func() {
DescribeTable("rejects flag combinations it cannot satisfy",
func(mutate func(), wantErr string) {
Expand Down
Loading