Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't apply CRD from raw resource more than one time #1523

Closed
nikkatalnikov opened this issue May 15, 2019 · 2 comments · Fixed by #1527
Closed

Can't apply CRD from raw resource more than one time #1523

nikkatalnikov opened this issue May 15, 2019 · 2 comments · Fixed by #1527
Assignees
Labels

Comments

@nikkatalnikov
Copy link

nikkatalnikov commented May 15, 2019

Hello. Having the following code, I have trouble to run

def runApp(): Unit = {
    sparkController.launchSparkTestDeployment()
    sparkController.cleanUpSparkTestDeployment()
}

twice like:

runApp()
// do next test
runApp()

Internals:

private val resource = new FileInputStream(new File(resourceName))
val crdContext: CustomResourceDefinitionContext = new CustomResourceDefinitionContext.Builder()
    .withGroup(crdGroup)
    .withName(crdInstanceName)
    .withScope(crdScope)
    .withPlural(crdPlural)
    .withVersion(crdVersion)
    .build()

  def launchSparkTestDeployment(): Unit = {
    val sparkCustomResource = client.customResource(crdContext)
    sparkCustomResource.create(crdNamespace, resource)

    client.pods()
      .inNamespace(crdNamespace)
      .withName(crdPodName)
      .waitUntilReady(20000, MILLISECONDS)

    val thread = Executors.newSingleThreadExecutor()

    thread.execute(new Runnable {
      override def run(): Unit =  client.pods()
        .inNamespace(crdNamespace)
        .withName(crdPodName)
        .watchLog(System.out)
    })

    Observable
      .interval(Duration(1000, MILLISECONDS))
      .map(_ => {
        val res = sparkCustomResource.get(crdNamespace, crdInstanceName)
        val JSONResp = new JSONObject(res)
        val decoded = decode[CustomObject](JSONResp.toString)

        decoded match {
          case Right(x) => x
          case Left(ex) => throw new RuntimeException(ex)
        }
      })
      .distinctUntilChanged(x => x.status)
      .takeWhile(x => {
        x.status match {
          case None => false
          case Some(status) => status.applicationState.state == SparkOperatorStatus.RunningState
        }
      })
      .toBlocking
      .subscribe(x => println(s"Monitoring CRD status while running: $x"))

    thread.shutdown()
  }

  def cleanUpSparkTestDeployment(): Unit = {
    client.customResource(crdContext).delete(crdNamespace, crdInstanceName)
  }

All the attempts spit the same error:

[info]   java.lang.IllegalStateException:
[info]   at io.fabric8.kubernetes.client.dsl.internal.RawCustomResourceOperationsImpl.makeCall(RawCustomResourceOperationsImpl.java:150)
[info]   at io.fabric8.kubernetes.client.dsl.internal.RawCustomResourceOperationsImpl.validateAndSubmitRequest(RawCustomResourceOperationsImpl.java:159)
[info]   at io.fabric8.kubernetes.client.dsl.internal.RawCustomResourceOperationsImpl.create(RawCustomResourceOperationsImpl.java:63)
[info]   at it_tests.utils.SparkController.launchSparkTestDeployment(SparkController.scala:35)
[info]   at it_tests.DataKeeperTest.runApp(DataKeeperTest.scala:22)
[info]   at it_tests.DataKeeperTest$$anonfun$4.apply(DataKeeperTest.scala:111)
[info]   at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
[info]   at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
[info]   at org.scalatest.Transformer.apply(Transformer.scala:22)
[info]   at org.scalatest.Transformer.apply(Transformer.scala:20)
[info]   ...
@rohanKanojia
Copy link
Member

I think we should add a method createOrReplace() like we have for other resources.

@rohanKanojia rohanKanojia self-assigned this May 15, 2019
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue May 15, 2019
@rohanKanojia
Copy link
Member

@nikkatalnikov : Raised a PR to fix this, would be available in next release :-)

rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants