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

Fix cross-namespace cli operations when a context is set #963

Merged
merged 2 commits into from
Jan 22, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class KubeClientFabric8(
.apiextensions()
.v1beta1()
.customResourceDefinitions()
.inAnyNamespace()
.list()
.getItems()
.asScala
Expand Down Expand Up @@ -159,6 +160,7 @@ class KubeClientFabric8(
logger.trace("Running the Fabric8 list command")
Try {
val res = cloudflowApps
.inAnyNamespace()
.list()
.getItems
.asScala
Expand All @@ -172,6 +174,7 @@ class KubeClientFabric8(
def getCloudflowAppStatus(appName: String): Try[models.ApplicationStatus] = withApplicationClient { cloudflowApps =>
Try {
val app = cloudflowApps
.inAnyNamespace()
.list()
.getItems()
.asScala
Expand Down Expand Up @@ -199,7 +202,12 @@ class KubeClientFabric8(
def getOperatorProtocolVersion(): Try[String] = withClient { client =>
for {
protocolVersionCM <- Try {
client.configMaps().withLabel(KubeClient.CloudflowProtocolVersionConfigMap).list().getItems()
client
.configMaps()
.inAnyNamespace()
.withLabel(KubeClient.CloudflowProtocolVersionConfigMap)
.list()
.getItems()
}
protocolVersion <- {
protocolVersionCM.size() match {
Expand Down Expand Up @@ -278,7 +286,8 @@ class KubeClientFabric8(
.addToData(dockerConfigSecret, Base64Helper.encode(config))
.build()

val prevImagePullSecret = client.secrets
val prevImagePullSecret = client
.secrets()
.inNamespace(namespace)
.list()
.getItems
Expand All @@ -289,7 +298,10 @@ class KubeClientFabric8(
case None =>
val config = DockerConfig(auths = Map(dockerRegistryURL -> configEntry))

client.secrets.inNamespace(namespace).create(secret(Serialization.jsonMapper().writeValueAsString(config)))
client
.secrets()
.inNamespace(namespace)
.create(secret(Serialization.jsonMapper().writeValueAsString(config)))
case Some(prev) =>
val data = prev
.getData()
Expand All @@ -301,7 +313,8 @@ class KubeClientFabric8(

val newConfig = prevConfig.copy(auths = prevConfig.auths.updated(dockerRegistryURL, configEntry))

client.secrets
client
.secrets()
.inNamespace(namespace)
.createOrReplace(secret(Serialization.jsonMapper().writeValueAsString(newConfig)))
}
Expand Down Expand Up @@ -417,13 +430,15 @@ class KubeClientFabric8(
Try {
content match {
case None =>
val current = client.secrets
val current = client
.secrets()
.inNamespace(name)
.withName(loggingSecretName)
.get()

if (current != null) {
client.secrets
client
.secrets()
.inNamespace(name)
.withName(loggingSecretName)
.delete()
Expand All @@ -442,7 +457,8 @@ class KubeClientFabric8(
.addToStringData(loggingSecretConfKey, v)
.build()

client.secrets
client
.secrets()
.inNamespace(name)
.withName(loggingSecretName)
.createOrReplace(secret)
Expand Down Expand Up @@ -474,6 +490,7 @@ class KubeClientFabric8(

client
.serviceAccounts()
.inNamespace(appId)
.createOrReplace(serviceAccount)
}
}
Expand Down Expand Up @@ -568,13 +585,16 @@ class KubeClientFabric8(
def deleteCloudflowApp(appName: String): Try[Unit] = withApplicationClient { cloudflowApps =>
Try {
val app = cloudflowApps
.inAnyNamespace()
.list()
.getItems()
.asScala
.find(_.getMetadata.getName == appName)
.getOrElse(throw CliException(s"""Cloudflow application "${appName}" not found"""))

cloudflowApps.delete(app)
cloudflowApps
.inAnyNamespace()
.delete(app)
}
}

Expand All @@ -600,7 +620,7 @@ class KubeClientFabric8(
case Some(ns) =>
client.secrets().inNamespace(ns)
case _ =>
client.secrets()
client.secrets().inAnyNamespace()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Fabric8KubeClientSpec extends AnyFlatSpec with Matchers with BeforeAndAfte
.once

server.expect.get
.withPath("/apis/cloudflow.lightbend.com/v1alpha1/namespaces/test/cloudflowapplications")
.withPath("/apis/cloudflow.lightbend.com/v1alpha1/cloudflowapplications")
.andReturn(
HttpURLConnection.HTTP_OK,
Source
Expand Down