Exemple #1
0
func main() {
	kubeClient, err := kcl.NewInCluster()
	if err != nil {
		log.Fatalf("Error creating new Kubernetes client (%s)", err)
	}
	apiClient, err := config.GetSwaggerClient(config.Spec.VersionsAPIURL)
	if err != nil {
		log.Fatalf("Error creating new swagger api client (%s)", err)
	}
	deisK8sResources := k8s.NewResourceInterfaceNamespaced(kubeClient, config.Spec.DeisNamespace)
	clusterID := data.NewClusterIDFromPersistentStorage(deisK8sResources.Secrets())
	installedDeisData := data.NewInstalledDeisData(deisK8sResources)
	availableVersion := data.NewAvailableVersionsFromAPI(
		apiClient,
		config.Spec.VersionsAPIURL,
	)
	availableComponentVersion := data.NewLatestReleasedComponent(deisK8sResources, availableVersion)

	pollDur := time.Duration(config.Spec.Polling) * time.Second
	// we want to do the following jobs according to our remote API interval:
	// 1. get latest stable deis component versions
	// 2. send diagnostic data, if appropriate
	glvdPeriodic := jobs.NewGetLatestVersionDataPeriodic(
		installedDeisData,
		clusterID,
		availableVersion,
		availableComponentVersion,
		pollDur,
	)

	svPeriodic := jobs.NewSendVersionsPeriodic(
		apiClient,
		clusterID,
		deisK8sResources,
		availableVersion,
		pollDur,
	)
	toDo := []jobs.Periodic{glvdPeriodic, svPeriodic}
	log.Printf("Starting periodic jobs at interval %s", pollDur)
	ch := jobs.DoPeriodic(toDo)
	defer close(ch)

	// Get a new router, with handler functions
	r := handlers.RegisterRoutes(mux.NewRouter(), availableVersion, deisK8sResources)
	// Bind to a port and pass our router in
	hostStr := fmt.Sprintf(":%s", config.Spec.Port)
	log.Printf("Serving on %s", hostStr)
	if err := http.ListenAndServe(hostStr, r); err != nil {
		close(ch)
		log.Println("Unable to open up TLS listener")
		log.Fatal("ListenAndServe: ", err)
	}
}
Exemple #2
0
// RegisterRoutes attaches handler functions to routes
func RegisterRoutes(
	r *mux.Router,
	availVers data.AvailableVersions,
	k8sResources *k8s.ResourceInterfaceNamespaced,
) *mux.Router {

	clusterID := data.NewClusterIDFromPersistentStorage(k8sResources.Secrets())
	r.Handle(componentsRoute, ComponentsHandler(
		data.NewInstalledDeisData(k8sResources),
		clusterID,
		data.NewLatestReleasedComponent(k8sResources, availVers),
	))
	r.Handle(idRoute, IDHandler(clusterID))
	doctorAPIClient, _ := config.GetSwaggerClient(config.Spec.DoctorAPIURL)
	r.Handle(doctorRoute, DoctorHandler(
		data.NewInstalledDeisData(k8sResources),
		k8s.NewRunningK8sData(k8sResources),
		clusterID,
		data.NewLatestReleasedComponent(k8sResources, availVers),
		doctorAPIClient,
	)).Methods("POST")
	return r
}
Exemple #3
0
//  sendVersions sends cluster version data
func sendVersionsImpl(
	apiClient *apiclient.WorkflowManager,
	clusterID data.ClusterID,
	k8sResources *k8s.ResourceInterfaceNamespaced,
	availableVersions data.AvailableVersions,
) error {
	cluster, err := data.GetCluster(
		data.NewInstalledDeisData(k8sResources),
		clusterID,
		data.NewLatestReleasedComponent(k8sResources, availableVersions),
	)
	if err != nil {
		log.Println("error getting installed components data")
		return err
	}

	_, err = apiClient.Operations.CreateClusterDetails(&operations.CreateClusterDetailsParams{Body: &cluster})
	if err != nil {
		log.Println("error sending diagnostic data")
		return err
	}
	return nil
}