Skip to content
This repository was archived by the owner on Dec 20, 2025. It is now read-only.

Commit e764f9f

Browse files
fix(liquibase): fix checkSum errors occurring with spinnaker upgrade (#6217) (#6231)
* fix(tests): added postgres migration test * fix(tests): hardcoded the docker image to create initial conditions * fix(liquibase): add validCheckSum values to fix failing changesets --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit ad1a8ef) Co-authored-by: Kiran Godishala <53332225+kirangodishala@users.noreply.github.com>
1 parent dd96b48 commit e764f9f

File tree

5 files changed

+142
-1
lines changed

5 files changed

+142
-1
lines changed

clouddriver-integration/src/test/java/com/netflix/spinnaker/clouddriver/BaseContainerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class BaseContainerTest {
4040

4141
protected final Network network = Network.newNetwork();
4242

43-
private static final int CLOUDDRIVER_PORT = 7002;
43+
protected static final int CLOUDDRIVER_PORT = 7002;
4444

4545
protected GenericContainer<?> clouddriverContainer;
4646

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright 2024 Salesforce, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.netflix.spinnaker.clouddriver;
18+
19+
import com.fasterxml.jackson.core.JsonProcessingException;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import java.time.Duration;
22+
import java.util.Map;
23+
import org.junit.jupiter.api.AfterAll;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.api.TestInstance;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
import org.testcontainers.containers.GenericContainer;
30+
import org.testcontainers.containers.PostgreSQLContainer;
31+
import org.testcontainers.containers.output.Slf4jLogConsumer;
32+
import org.testcontainers.containers.wait.strategy.Wait;
33+
import org.testcontainers.junit.jupiter.Testcontainers;
34+
import org.testcontainers.utility.DockerImageName;
35+
36+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
37+
@Testcontainers
38+
public class PostgresMigrationContainerTest extends BaseContainerTest {
39+
40+
private static final Logger logger =
41+
LoggerFactory.getLogger(PostgresMigrationContainerTest.class);
42+
43+
private static final String POSTGRES_NETWORK_ALIAS = "postgresHost";
44+
45+
private static final int POSTGRES_PORT = 5432;
46+
47+
private PostgreSQLContainer<?> postgres;
48+
49+
private GenericContainer<?> clouddriverInitialContainer;
50+
51+
// this is the latest image that is still running on liquibase 3.10.3 which create the conditions
52+
// similar to real scenario so that test identifies when validChecksums are not added in the later
53+
// version of clouddriver where higher liquibase versions are used
54+
private static final DockerImageName previousDockerImageName =
55+
DockerImageName.parse(
56+
"us-docker.pkg.dev/spinnaker-community/docker/clouddriver:5.82.2-dev-release-1.32.x-7a8e6e8b3-202406051721-unvalidated");
57+
58+
private String jdbcUrl = "";
59+
60+
@BeforeEach
61+
void setup() throws Exception {
62+
postgres =
63+
new PostgreSQLContainer<>("postgres:15")
64+
.withDatabaseName("clouddriver")
65+
.withUsername("postgres")
66+
.withPassword("postgres")
67+
.withNetwork(network)
68+
.withNetworkAliases(POSTGRES_NETWORK_ALIAS)
69+
.withInitScript("postgres_init.sql")
70+
.withReuse(true);
71+
postgres.start();
72+
jdbcUrl =
73+
String.format("jdbc:postgresql://%s:%d/clouddriver", POSTGRES_NETWORK_ALIAS, POSTGRES_PORT);
74+
75+
// Start the first clouddriver(from previous release) container so that all the db changelog
76+
// sets are executed
77+
clouddriverInitialContainer =
78+
new GenericContainer(previousDockerImageName)
79+
.withNetwork(network)
80+
.withExposedPorts(CLOUDDRIVER_PORT)
81+
.waitingFor(Wait.forHealthcheck().withStartupTimeout(Duration.ofSeconds(120)))
82+
.dependsOn(postgres)
83+
.withEnv("SPRING_APPLICATION_JSON", getSpringApplicationJson());
84+
clouddriverInitialContainer.start();
85+
Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(logger);
86+
clouddriverInitialContainer.followOutput(logConsumer);
87+
clouddriverInitialContainer.stop();
88+
89+
// Start the second clouddriver(latest) container to validate migration
90+
clouddriverContainer
91+
.dependsOn(postgres)
92+
.withEnv("SPRING_APPLICATION_JSON", getSpringApplicationJson())
93+
.start();
94+
95+
clouddriverContainer.followOutput(logConsumer);
96+
}
97+
98+
private String getSpringApplicationJson() throws JsonProcessingException {
99+
logger.info("----------- jdbcUrl: '{}'", jdbcUrl);
100+
Map<String, String> connectionPool =
101+
Map.of("jdbcUrl", jdbcUrl, "user", "clouddriver_service", "password", "c10uddriver");
102+
Map<String, String> migration =
103+
Map.of("jdbcUrl", jdbcUrl, "user", "clouddriver_migrate", "password", "c10uddriver");
104+
105+
Map<String, Object> properties =
106+
Map.of(
107+
"sql.enabled",
108+
"true",
109+
"services.fiat.baseUrl",
110+
"http://nowhere",
111+
"sql.connectionPool",
112+
connectionPool,
113+
"redis.enabled",
114+
"false",
115+
"sql.migration",
116+
migration);
117+
ObjectMapper mapper = new ObjectMapper();
118+
return mapper.writeValueAsString(properties);
119+
}
120+
121+
@AfterAll
122+
void cleanupOnce() {
123+
if (clouddriverContainer != null) {
124+
clouddriverContainer.stop();
125+
}
126+
127+
if (postgres != null) {
128+
postgres.stop();
129+
}
130+
}
131+
132+
@Test
133+
void testHealthCheckWithPostgres() throws Exception {
134+
super.testHealthCheck();
135+
}
136+
}

clouddriver-sql/src/main/resources/db/changelog/20180919-initial-schema.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ databaseChangeLog:
8282
tableName: task_states
8383

8484
- changeSet:
85+
validCheckSum: 8:f0bfebd55de9168e38a8ef9c7217c610
8586
id: mysql-change-state-stauts-to-enum-type
8687
author: robzienert
8788
changes:
@@ -171,6 +172,7 @@ databaseChangeLog:
171172
tableName: task_results
172173

173174
- changeSet:
175+
validCheckSum: 8:d6f5eedc195011826620cc0355e8352d
174176
id: mysql-revert-change-state-stauts-to-enum-type
175177
author: afeldman
176178
changes:

clouddriver-sql/src/main/resources/db/changelog/20181120-cats.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ databaseChangeLog:
216216
newDataType: varchar(255)
217217

218218
- changeSet:
219+
validCheckSum: 8:03b00d0af09f2e7081d187f246ea4d26
219220
id: application-index
220221
author: afeldman
221222
changes:

clouddriver-sql/src/main/resources/db/changelog/20190913-task-sagaids.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ databaseChangeLog:
44
dbms: postgresql
55
remove: afterColumn
66
- changeSet:
7+
validCheckSum: 8:91cfabe4a8fa0517124436ef9675708e
78
id: add-task-sagaids-column
89
author: robzienert
910
changes:
@@ -19,6 +20,7 @@ databaseChangeLog:
1920
columnName: saga_ids
2021

2122
- changeSet:
23+
validCheckSum: 8:9601af668599fbc12e338b9b84c66f56
2224
id: mysql-update-state-enum-values
2325
author: robzienert
2426
changes:

0 commit comments

Comments
 (0)