Skip to content

Commit

Permalink
Pick Namespace/Project from kubeconfig or assume default
Browse files Browse the repository at this point in the history
As reported in #1 , this project doesn't seem to be working for
users who have namespace set other than default.
  • Loading branch information
rohanKanojia committed Oct 16, 2019
1 parent 8faf9eb commit 785a571
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/main/java/io/fabric8/podset/operator/PodSetOperatorMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,26 @@
import io.fabric8.podset.operator.crd.PodSet;
import io.fabric8.podset.operator.crd.PodSetList;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Main Class for Operator, you can run this sample using this command:
*
* mvn exec:java -Dexec.mainClass=io.fabric8.podset.operator.PodSetOperatorMain
*/
public class PodSetOperatorMain {
public static Logger logger = Logger.getLogger(PodSetOperatorMain.class.getName());

public static void main(String args[]) {
try (KubernetesClient client = new DefaultKubernetesClient()) {
String namespace = client.getNamespace();
if (namespace == null) {
logger.log(Level.INFO, "No namespace found via config, assuming default.");
namespace = "default";
}

logger.log(Level.INFO, "Using namespace : " + namespace);
CustomResourceDefinition podSetCustomResourceDefinition = new CustomResourceDefinitionBuilder()
.withNewMetadata().withName("podsets.demo.k8s.io").endMetadata()
.withNewSpec()
Expand All @@ -46,7 +57,7 @@ public static void main(String args[]) {
MixedOperation<PodSet, PodSetList, DoneablePodSet, Resource<PodSet, DoneablePodSet>> podSetClient = client.customResources(podSetCustomResourceDefinition, PodSet.class, PodSetList.class, DoneablePodSet.class);
SharedIndexInformer<Pod> podSharedIndexInformer = informerFactory.sharedIndexInformerFor(Pod.class, PodList.class, 10 * 60 * 1000);
SharedIndexInformer<PodSet> podSetSharedIndexInformer = informerFactory.sharedIndexInformerForCustomResource(podSetCustomResourceDefinitionContext, PodSet.class, PodSetList.class, 10 * 60 * 1000);
PodSetController podSetController = new PodSetController(client, podSetClient, podSharedIndexInformer, podSetSharedIndexInformer);
PodSetController podSetController = new PodSetController(client, podSetClient, podSharedIndexInformer, podSetSharedIndexInformer, namespace);

podSetController.create();
informerFactory.startAllRegisteredInformers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public class PodSetController {
public static Logger logger = Logger.getLogger(PodSetController.class.getName());
public static String APP_LABEL = "app";

public PodSetController(KubernetesClient kubernetesClient, MixedOperation<PodSet, PodSetList, DoneablePodSet, Resource<PodSet, DoneablePodSet>> podSetClient, SharedIndexInformer<Pod> podInformer, SharedIndexInformer<PodSet> podSetInformer) {
public PodSetController(KubernetesClient kubernetesClient, MixedOperation<PodSet, PodSetList, DoneablePodSet, Resource<PodSet, DoneablePodSet>> podSetClient, SharedIndexInformer<Pod> podInformer, SharedIndexInformer<PodSet> podSetInformer, String namespace) {
this.kubernetesClient = kubernetesClient;
this.podSetClient = podSetClient;
this.podSetLister = new Lister<>(podSetInformer.getIndexer(), "default");
this.podSetLister = new Lister<>(podSetInformer.getIndexer(), namespace);
this.podSetInformer = podSetInformer;
this.podLister = new Lister<>(podInformer.getIndexer(), "default");
this.podLister = new Lister<>(podInformer.getIndexer(), namespace);
this.podInformer = podInformer;
this.workqueue = new ArrayBlockingQueue<>(1024);
}
Expand Down

0 comments on commit 785a571

Please sign in to comment.