From 1bc15e3c6362c90bba45cc14606c772bb59c6e30 Mon Sep 17 00:00:00 2001 From: David O'Riordan Date: Sat, 5 Nov 2022 11:50:42 +0000 Subject: [PATCH] Remove CRD example (#347) --- .../examples/customresources/CreateCRD.scala | 75 ------------------- 1 file changed, 75 deletions(-) delete mode 100644 examples/src/main/scala/skuber/examples/customresources/CreateCRD.scala diff --git a/examples/src/main/scala/skuber/examples/customresources/CreateCRD.scala b/examples/src/main/scala/skuber/examples/customresources/CreateCRD.scala deleted file mode 100644 index b106fbbf..00000000 --- a/examples/src/main/scala/skuber/examples/customresources/CreateCRD.scala +++ /dev/null @@ -1,75 +0,0 @@ -package skuber.examples.customresources - -import skuber.{k8sInit,K8SException} -import skuber.ResourceSpecification.Scope -import skuber.apiextensions.CustomResourceDefinition - -import akka.actor.ActorSystem - -import scala.util.{Success, Failure} - -/** - * @author David O'Riordan - * Create the Team and ServiceSupport CRDs on k8s - */ -object CreateCRD extends App { - - // CRD for the organizations teams, each team should be represented by a single Team resource. - // A teams resources may in some cases (we assume for demo purposes) exist in multiple namespaces, so scope of Team - // is Clustered rather than the default of Namespaced - val teamCrd = CustomResourceDefinition( - name = "teams.examples.skuber.io", - kind = "Team", - scope = Scope.Cluster) - - // CRD for the organizations service support (SUP) information, each service should have one SUP resource - // Scope is default i.e. Namespaced - each SUP resource should be in the same namespace as the resources of the - // corresponding service - val svcSupportCrd = CustomResourceDefinition( - name = "servicesupports.examples.skuber.io", - kind = "ServiceSupport", - shortNames = "sup" :: Nil) - - implicit val system = ActorSystem() - implicit val dispatcher = system.dispatcher - - val k8s = k8sInit - - val saveCRDs = for { - _ <- save(teamCrd) - s <- save(svcSupportCrd) - } yield s - - saveCRDs onComplete { - case Success(_) => - System.out.println("done!") - k8s.close - system.terminate().foreach { f => - System.exit(0) - } - case Failure(ex) => - System.err.println("Failed: " + ex) - k8s.close - system.terminate().foreach { f => - System.exit(1) - } - } - - def save(crd: CustomResourceDefinition) = { - k8s create (crd) recoverWith { - case notFound: K8SException if notFound.status.code.contains(404) => { - // probably due to running against pre v1.7 cluster where CRDs don't exist as a resource kind - System.err.println("Unable to create CRD - please check that your k8s cluster is at v1.7 or above") - throw notFound - } - case alreadyExists: K8SException if alreadyExists.status.code.contains(409) => - // update needs to use the rcurrent resource version of existing resource in order to be accepted by k8s - k8s get[CustomResourceDefinition] (crd.name) flatMap { existing => - val currentVersion = existing.metadata.resourceVersion - val newMeta = crd.metadata.copy(resourceVersion = currentVersion) - val updatedObj = crd.copy(metadata = newMeta) - k8s update (updatedObj) - } - } - } -} \ No newline at end of file