コード例 #1
0
ファイル: main.go プロジェクト: aclisp/kubecon
func updateConfig(c *gin.Context) {
	if c.MustGet(gin.AuthUserKey).(string) != "admin" {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": "Unauthorized"})
		return
	}

	kubeclient.KubeConfig.APIServerURL = c.PostForm("inputAPIServerURL")
	kubeclient.KubeConfig.Username = c.PostForm("inputUsername")
	kubeclient.KubeConfig.Password = c.PostForm("inputPassword")
	kubeclient.SaveKubeConfig()
	kubeclient.Init()
	c.Redirect(http.StatusMovedPermanently, "/")
}
コード例 #2
0
ファイル: main.go プロジェクト: aclisp/kubecon
func main() {
	defer glog.Flush()

	flag.StringVar(&kubeclient.KubeConfigFile, "kubeconfig", "kubeconfig.json", "Specify the target API server")
	flag.Set("logtostderr", "true")
	flag.Parse()

	kubeclient.Init()
	portMapping = regexp.MustCompile(`PortMapping\((.*)\)`)

	r := gin.Default()
	r.Static("/js", "js")
	r.Static("/css", "css")
	r.Static("/fonts", "fonts")
	r.Static("/img", "img")
	r.LoadHTMLGlob("pages/*.html")

	a := r.Group("/", gin.BasicAuth(gin.Accounts{
		"admin":    "secretsigma",
		"bamboo":   "oobmab",
		"default":  "test123",
		"rds":      "rrddss",
		"rds-test": "rrddsstt",
	}))

	a.GET("/", overview)
	a.GET("/namespaces/:ns", listOthersInNamespace)
	a.GET("/namespaces/:ns/pods", listPodsInNamespace)
	a.GET("/namespaces/:ns/pods/:po", describePod)
	a.GET("/namespaces/:ns/pods/:po/log", readPodLog)
	a.GET("/namespaces/:ns/pods/:po/containers/:ct/log", readContainerLog)
	a.GET("/namespaces/:ns/pods/:po/edit", editPod)
	a.GET("/namespaces/:ns/replicationcontrollers/:rc/edit", editReplicationController)
	a.GET("/namespaces/:ns/services/:svc/edit", editService)
	a.GET("/namespaces/:ns/endpoints/:ep/edit", editEndpoints)
	a.GET("/nodes/:no/edit", editNode)
	a.GET("/namespaces/:ns/events", listEventsInNamespace)
	a.GET("/nodes", listNodes)
	a.GET("/nodes/:no", describeNode)
	a.GET("/help", help)
	a.GET("/config", config)

	a.GET("/namespaces/:ns/replicationcontrollers.form", showReplicationControllerForm)
	a.POST("/namespaces/:ns/replicationcontrollers", createReplicationController)

	a.GET("/namespaces/:ns/services.form", showServiceForm)
	a.POST("/namespaces/:ns/services", createService)

	a.POST("/namespaces/:ns/pods.form", showPodsForm)
	a.POST("/namespaces/:ns/pods", performPodsAction)

	a.POST("/config/update", updateConfig)
	a.POST("/namespaces/:ns/pods/:po/update", updatePod)
	a.POST("/namespaces/:ns/pods/:po/export", updateReplicationControllerWithPod)
	a.POST("/namespaces/:ns/pods/:po/import", updatePodWithReplicationController)
	a.POST("/namespaces/:ns/services/:svc/update", updateService)
	a.POST("/namespaces/:ns/services/:svc/delete", deleteService)
	a.POST("/namespaces/:ns/endpoints/:ep/update", updateEndpoints)
	a.POST("/namespaces/:ns/endpoints/:ep/delete", deleteEndpoints)
	a.POST("/namespaces/:ns/replicationcontrollers/:rc/update", updateReplicationController)
	a.POST("/namespaces/:ns/replicationcontrollers/:rc/delete", deleteReplicationController)
	a.POST("/nodes/:no/update", updateNode)
	a.POST("/nodes/:no/delete", deleteNode)

	certFile := "kubecon.crt"
	keyFile := "kubecon.key"
	alternateIPs := []net.IP{net.ParseIP("61.160.36.122")}
	alternateDNS := []string{"kubecon"}
	if err := util.GenerateSelfSignedCert("61.160.36.122", certFile, keyFile, alternateIPs, alternateDNS); err != nil {
		glog.Errorf("Unable to generate self signed cert: %v", err)
	} else {
		glog.Infof("Using self-signed cert (%s, %s)", certFile, keyFile)
	}
	r.RunTLS(":8080", certFile, keyFile)
}