Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-09-25 10:10:25 +0300
committerShinya Maeda <shinya@gitlab.com>2017-09-25 10:10:25 +0300
commitd4fa672c20657a1c7d2fcfa25e9798e7ccdbf39d (patch)
tree416f477c9f574116d74cbf6687b7b18a09f550d5 /app/controllers
parente2b195b2748c88e276163d44cdeff5b210f2522c (diff)
Create Kubernetes cluster on GKE from k8s service
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/google_api/authorizations_controller.rb27
-rw-r--r--app/controllers/projects/clusters_controller.rb102
2 files changed, 129 insertions, 0 deletions
diff --git a/app/controllers/google_api/authorizations_controller.rb b/app/controllers/google_api/authorizations_controller.rb
new file mode 100644
index 00000000000..e99c38025b8
--- /dev/null
+++ b/app/controllers/google_api/authorizations_controller.rb
@@ -0,0 +1,27 @@
+module GoogleApi
+ class AuthorizationsController < ApplicationController
+ # callback_google_api_authorizations GET|POST /google_api/authorizations/callback(.:format) google_api/authorizations#callback
+ ##
+ # TODO:
+ # - Is it ok to use both "http://localhost:3000/google_api/authorizations/callback"(For login) and "http://localhost:3000/google_api/authorizations/callback"(For API token)
+ def callback
+ session[access_token_key] = api_client.get_token(params[:code])
+
+ if params[:state]
+ redirect_to params[:state]
+ else
+ redirect_to root_url
+ end
+ end
+
+ def api_client
+ @api_client ||=
+ GoogleApi::Authentication.new(nil, callback_google_api_authorizations_url)
+ end
+
+ def access_token_key
+ # :"#{api_client.scope}_access_token"
+ :"hoge_access_token" # TODO:
+ end
+ end
+end
diff --git a/app/controllers/projects/clusters_controller.rb b/app/controllers/projects/clusters_controller.rb
new file mode 100644
index 00000000000..5c9319f661a
--- /dev/null
+++ b/app/controllers/projects/clusters_controller.rb
@@ -0,0 +1,102 @@
+class Projects::ClustersController < Projects::ApplicationController
+ # before_action :authenticate_google_api
+ before_action :cluster
+
+ # before_action :authorize_admin_clusters! # TODO: Authentication
+
+ def index
+ if cluster
+ redirect_to action: 'edit'
+ else
+ redirect_to action: 'new'
+ end
+ end
+
+ ##
+ # TODO:
+ # - Show form for "Create on Google Container Engine"
+ # - Show form for "Use existing kubernets cluster"
+ # - If user has not authroized yet, Show "Sign in with Google" button
+ # - If user has already authroized, Skip "Sign in with Google" button
+ # - user.is_authenticated_for_gcp?
+ # - user.authenticate_for_gcp!
+ # - Create this module which can be used from view
+ def new
+ unless session[access_token_key]
+ @authorize_url = api_client.authorize_url
+ end
+ end
+
+ ##
+ # TODO:
+ # - If create on GKE, Use Google::Apis::ContainerV1::ContainerService
+ # - If create manually, save in db (Prob, Project > Setting)
+ # - Dry up with Service
+ def create
+ redirect_to action: 'index'
+ end
+
+ # TODO: Show results/status. Edits Swtich for enable/disable.
+ # If created with GKE, non-editable form. enable/disable switch.
+ # If created manually, editable form. enable/disable switch.
+ # GKE params are on-off swtich
+ # Manul params are on-off swtich, Endpoint, CACert, k8s Token, Proj namespace.
+ def edit
+ unless session[access_token_key]
+ @authorize_url = api_client.authorize_url
+ end
+ end
+
+ def update
+ cluster.update(schedule_params)
+ render :edit
+ end
+
+ # In presenter
+ # TODO: Generate a link to the cluster on GKE
+
+ def gcp_projects
+ # api_client.blah
+ # TODO: Return all avaiable GCP Projects.
+ # TODO: Return json
+ # TODO: Dry with concern
+ end
+
+ def gke_zones
+ # api_client.blah
+ # TODO: Return all avaiable zones on GKE.
+ # TODO: Return json
+ # TODO: Dry with concern
+ end
+
+ private
+
+ # def authenticate_google_api
+ # if cluster&.on_gke? && session[access_token_key].blank?
+ # redirect_to api_client.authorize_url(callback_import_url)
+ # end
+ # end
+
+ def cluster
+ # Each project has only one cluster, for now. In the future iteraiton, we'll support multiple clusters
+ @cluster ||= project.clusters.first
+ end
+
+ def cluster_params
+ params.require(:cluster).permit(:aaa)
+ end
+
+ def api_client
+ @api_client ||=
+ GoogleApi::CloudPlatform::Client.new(
+ session[access_token_key],
+ callback_google_api_authorizations_url,
+ state: namespace_project_clusters_url.to_s
+ )
+ end
+
+ def access_token_key
+ # :"#{api_client.scope}_access_token"
+ :"hoge_access_token" # TODO:
+ end
+end