Skip to content

Instantly share code, notes, and snippets.

@Configuration
class SumNumbersConfiguration {
@Bean
fun generateNumbers(): Supplier<Message<String>> = Supplier<Message<String>> {
val randomNumber1 = Random.nextInt(100)
val randomNumber2 = Random.nextInt(100)
print("$randomNumber1+$randomNumber2=")
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.6.9"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.6.21"
kotlin("plugin.spring") version "1.6.21"
}
group = "com.raphaeldelio"
@RunWith(SpringRunner::class)
@SpringBootTest
@ContextConfiguration(
initializers = [
GoogleCloudStorageTestContainerInitializer::class
]
)
class GcsIntegrationApplicationTests {
@Autowired
/**
* This configuration is used to override the default Google Cloud Storage client with the one created by Testcontainers.
*/
@Configuration
class GoogleCloudStorageConfiguration {
@Value("\${gcs.port}")
private lateinit var gcsContainerPort: String
@Bean
open class GoogleCloudStorageTestContainerInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {
private lateinit var container: GoogleCloudStorageTestContainer
override fun initialize(configurableApplicationContext: ConfigurableApplicationContext) {
container = createContainer()
container.start()
applyConfiguration(configurableApplicationContext)
/**
* [GoogleCloudStorageTestContainer] is a [GenericContainer] that provides a Google Cloud Storage service.
*/
class GoogleCloudStorageTestContainer : GenericContainer<GoogleCloudStorageTestContainer>(
DockerImageName.parse("fsouza/fake-gcs-server")
) {
init {
withExposedPorts(4443)
withCreateContainerCmdModifier {
it.withEntrypoint("/bin/fake-gcs-server", "-scheme", "http")
@SpringBootApplication
@EnableScheduling
class GcsIntegrationApplication(
private val storage: Storage
) {
@Scheduled(fixedDelay = 100)
fun schedule() {
mkdirs()
downloadFiles()
# Deploy singleton instance in the whole cluster for some unique data sources, like kube-state-metrics
apiVersion: apps/v1
kind: Deployment
metadata:
name: heartbeat
namespace: monitoring
labels:
k8s-app: heartbeat
spec:
selector:
@raphaeldelio
raphaeldelio / heartbeat-authorization.yml
Created November 4, 2020 20:46
heartbeat-authorization.yml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: heartbeat
subjects:
- kind: ServiceAccount
name: heartbeat
namespace: monitoring
roleRef:
kind: ClusterRole
@raphaeldelio
raphaeldelio / heartbeat-cm.yml
Last active July 3, 2021 15:17
Heartbeat for Kubernetes ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: heartbeat-deployment-config
namespace: monitoring
labels:
k8s-app: heartbeat
data:
heartbeat.yml: |-
heartbeat.monitors: