Esempio n. 1
0
// Returns Clientset for the given cluster.
func GetClientsetForCluster(cluster *federation_v1beta1.Cluster) (*fedclientset.Clientset, error) {
	clusterConfig, err := BuildClusterConfig(cluster)
	if err != nil && clusterConfig != nil {
		clientset := fedclientset.NewForConfigOrDie(restclient.AddUserAgent(clusterConfig, userAgentName))
		return clientset, nil
	}
	return nil, err
}
Esempio n. 2
0
func (a *adminConfig) FederationClientset(context, kubeconfigPath string) (*fedclient.Clientset, error) {
	fedConfig := a.getClientConfig(context, kubeconfigPath)
	fedClientConfig, err := fedConfig.ClientConfig()
	if err != nil {
		return nil, err
	}

	return fedclient.NewForConfigOrDie(fedClientConfig), nil
}
func TestUpdateClusterStatusOK(t *testing.T) {
	clusterName := "foobarCluster"
	// create dummy httpserver
	testClusterServer := httptest.NewServer(createHttptestFakeHandlerForCluster(true))
	defer testClusterServer.Close()
	federationCluster := newCluster(clusterName, testClusterServer.URL)
	federationClusterList := newClusterList(federationCluster)

	testFederationServer := httptest.NewServer(createHttptestFakeHandlerForFederation(federationClusterList, true))
	defer testFederationServer.Close()

	restClientCfg, err := clientcmd.BuildConfigFromFlags(testFederationServer.URL, "")
	if err != nil {
		t.Errorf("Failed to build client config")
	}
	federationClientSet := federationclientset.NewForConfigOrDie(restclient.AddUserAgent(restClientCfg, "cluster-controller"))

	// Override KubeconfigGetterForCluster to avoid having to setup service accounts and mount files with secret tokens.
	originalGetter := controllerutil.KubeconfigGetterForCluster
	controllerutil.KubeconfigGetterForCluster = func(c *federationv1beta1.Cluster) clientcmd.KubeconfigGetter {
		return func() (*clientcmdapi.Config, error) {
			return &clientcmdapi.Config{}, nil
		}
	}

	manager := NewclusterController(federationClientSet, 5)
	err = manager.UpdateClusterStatus()
	if err != nil {
		t.Errorf("Failed to Update Cluster Status: %v", err)
	}
	clusterStatus, found := manager.clusterClusterStatusMap[clusterName]
	if !found {
		t.Errorf("Failed to Update Cluster Status")
	} else {
		if (clusterStatus.Conditions[1].Status != v1.ConditionFalse) || (clusterStatus.Conditions[1].Type != federationv1beta1.ClusterOffline) {
			t.Errorf("Failed to Update Cluster Status")
		}
	}

	// Reset KubeconfigGetterForCluster
	controllerutil.KubeconfigGetterForCluster = originalGetter
}
Esempio n. 4
0
func StartControllers(s *options.CMServer, restClientCfg *restclient.Config) error {
	glog.Infof("Loading client config for cluster controller %q", "cluster-controller")
	ccClientset := federationclientset.NewForConfigOrDie(restclient.AddUserAgent(restClientCfg, "cluster-controller"))
	glog.Infof("Running cluster controller")
	go clustercontroller.NewclusterController(ccClientset, s.ClusterMonitorPeriod.Duration).Run()
	dns, err := dnsprovider.InitDnsProvider(s.DnsProvider, s.DnsConfigFile)
	if err != nil {
		glog.Fatalf("Cloud provider could not be initialized: %v", err)
	}

	discoveryClient := discovery.NewDiscoveryClientForConfigOrDie(restClientCfg)
	serverResources, err := discoveryClient.ServerResources()
	if err != nil {
		glog.Fatalf("Could not find resources from API Server: %v", err)
	}

	glog.Infof("Loading client config for namespace controller %q", "namespace-controller")
	nsClientset := federationclientset.NewForConfigOrDie(restclient.AddUserAgent(restClientCfg, "namespace-controller"))
	namespaceController := namespacecontroller.NewNamespaceController(nsClientset)
	glog.Infof("Running namespace controller")
	namespaceController.Run(wait.NeverStop)

	secretcontrollerClientset := federationclientset.NewForConfigOrDie(restclient.AddUserAgent(restClientCfg, "secret-controller"))
	secretcontroller := secretcontroller.NewSecretController(secretcontrollerClientset)
	secretcontroller.Run(wait.NeverStop)

	configmapcontrollerClientset := federationclientset.NewForConfigOrDie(restclient.AddUserAgent(restClientCfg, "configmap-controller"))
	configmapcontroller := configmapcontroller.NewConfigMapController(configmapcontrollerClientset)
	configmapcontroller.Run(wait.NeverStop)

	daemonsetcontrollerClientset := federationclientset.NewForConfigOrDie(restclient.AddUserAgent(restClientCfg, "daemonset-controller"))
	daemonsetcontroller := daemonset.NewDaemonSetController(daemonsetcontrollerClientset)
	daemonsetcontroller.Run(wait.NeverStop)

	replicaSetClientset := federationclientset.NewForConfigOrDie(restclient.AddUserAgent(restClientCfg, replicasetcontroller.UserAgentName))
	replicaSetController := replicasetcontroller.NewReplicaSetController(replicaSetClientset)
	go replicaSetController.Run(s.ConcurrentReplicaSetSyncs, wait.NeverStop)

	deploymentClientset := federationclientset.NewForConfigOrDie(restclient.AddUserAgent(restClientCfg, deploymentcontroller.UserAgentName))
	deploymentController := deploymentcontroller.NewDeploymentController(deploymentClientset)
	// TODO: rename s.ConcurentReplicaSetSyncs
	go deploymentController.Run(s.ConcurrentReplicaSetSyncs, wait.NeverStop)

	if controllerEnabled(s.Controllers, serverResources, ingresscontroller.ControllerName, ingresscontroller.RequiredResources, true) {
		glog.Infof("Loading client config for ingress controller %q", "ingress-controller")
		ingClientset := federationclientset.NewForConfigOrDie(restclient.AddUserAgent(restClientCfg, "ingress-controller"))
		ingressController := ingresscontroller.NewIngressController(ingClientset)
		glog.Infof("Running ingress controller")
		ingressController.Run(wait.NeverStop)
	}

	glog.Infof("Loading client config for service controller %q", servicecontroller.UserAgentName)
	scClientset := federationclientset.NewForConfigOrDie(restclient.AddUserAgent(restClientCfg, servicecontroller.UserAgentName))
	servicecontroller := servicecontroller.New(scClientset, dns, s.FederationName, s.ServiceDnsSuffix, s.ZoneName, s.ZoneID)
	glog.Infof("Running service controller")
	if err := servicecontroller.Run(s.ConcurrentServiceSyncs, wait.NeverStop); err != nil {
		glog.Errorf("Failed to start service controller: %v", err)
	}

	select {}
}