Skip to content

Commit

Permalink
Fix skipper_manifest.data column oid to text conversion that was missed.
Browse files Browse the repository at this point in the history
Fixes spring-cloud#5715

Cherry picked from 2.11.x
  • Loading branch information
Corneil du Plessis authored and cppwfs committed Mar 4, 2024
1 parent 67ff52a commit 64f8bd0
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.skipper.server.db.migration.postgresql;

import org.flywaydb.core.api.migration.Context;

import org.springframework.cloud.dataflow.common.flyway.AbstractMigration;
import org.springframework.cloud.skipper.server.db.migration.PostgreSQLTextToOID;

/**
* Fix missing skipper_manifest.data conversion from oid to text.
*
* @author Corneil du Plessis
*/
public class V4__ChangeTextTypes_SkipperManifest extends AbstractMigration {
public V4__ChangeTextTypes_SkipperManifest() {
super(null);
}

@Override
public void migrate(Context context) {
PostgreSQLTextToOID.convertColumnFromOID("skipper_manifest", "id", "data", context.getConfiguration().getDataSource());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,7 @@
package org.springframework.cloud.skipper.server.db.migration;

import java.util.Collections;

import jakarta.persistence.EntityManagerFactory;
import javax.persistence.EntityManagerFactory;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
Expand All @@ -28,13 +27,20 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.session.SessionAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.common.security.CommonSecurityAutoConfiguration;
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryDeployerAutoConfiguration;
import org.springframework.cloud.deployer.spi.kubernetes.KubernetesAutoConfiguration;
import org.springframework.cloud.deployer.spi.local.LocalDeployerAutoConfiguration;
import org.springframework.cloud.skipper.domain.ConfigValues;
import org.springframework.cloud.skipper.domain.Info;
import org.springframework.cloud.skipper.domain.Manifest;
import org.springframework.cloud.skipper.domain.Package;
import org.springframework.cloud.skipper.domain.PackageMetadata;
import org.springframework.cloud.skipper.domain.Release;
import org.springframework.cloud.skipper.server.EnableSkipperServer;
import org.springframework.cloud.skipper.server.domain.AppDeployerData;
import org.springframework.cloud.skipper.server.repository.jpa.AppDeployerDataRepository;
import org.springframework.cloud.skipper.server.repository.jpa.ReleaseRepository;
import org.springframework.cloud.skipper.server.util.ManifestUtils;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
Expand All @@ -59,6 +65,10 @@ public abstract class AbstractSkipperSmokeTest {
@Autowired
AppDeployerDataRepository appDeployerDataRepository;

@Autowired
ReleaseRepository releaseRepository;


@Autowired
Environment environment;

Expand All @@ -78,14 +88,47 @@ public void testStart() {
assertThat(deployerData.getId()).isNotEqualTo(0);
assertThat(deployerData.getDeploymentDataAsMap()).isNotEmpty();
assertThat(deployerData.getDeploymentDataAsMap()).containsEntry("a", "b");

Release release = createRelease();
releaseRepository.save(release);
String kind = ManifestUtils.resolveKind(release.getManifest().getData());
assertThat(kind).isNotBlank();
Release loaded = releaseRepository.findTopByNameOrderByVersionDesc(release.getName());
String loadedKind = ManifestUtils.resolveKind(loaded.getManifest().getData());

assertThat(loadedKind).isEqualTo(kind);

logger.info("completed:{}", getClass().getSimpleName());
}

private static Release createRelease() {
Info info = Info.createNewInfo("some info");
Manifest manifest = new Manifest();
manifest.setData("kind: Deployment\nmetadata:\n name: abc\n");
Release release = new Release();
release.setName("abc");
release.setPlatformName("default");
release.setConfigValues(new ConfigValues());

Package pkg = new Package();
PackageMetadata packageMetadata1 = new PackageMetadata();
packageMetadata1.setApiVersion("skipper.spring.io/v1");
packageMetadata1.setKind("SpringCloudDeployerApplication");
packageMetadata1.setRepositoryId(1L);
packageMetadata1.setName("package1");
packageMetadata1.setVersion("1.0.0");
pkg.setMetadata(packageMetadata1);
release.setPkg(pkg);
release.setVersion(1);
release.setInfo(info);
release.setManifest(manifest);
return release;
}

@SpringBootApplication(exclude = {CloudFoundryDeployerAutoConfiguration.class,
LocalDeployerAutoConfiguration.class,
KubernetesAutoConfiguration.class,
SessionAutoConfiguration.class,
CommonSecurityAutoConfiguration.class
SessionAutoConfiguration.class
})
@EnableSkipperServer
public static class LocalTestSkipperServer {
Expand Down

0 comments on commit 64f8bd0

Please sign in to comment.