diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-09-25 10:10:25 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-09-25 10:10:25 +0300 |
commit | d4fa672c20657a1c7d2fcfa25e9798e7ccdbf39d (patch) | |
tree | 416f477c9f574116d74cbf6687b7b18a09f550d5 /app/controllers/projects/clusters_controller.rb | |
parent | e2b195b2748c88e276163d44cdeff5b210f2522c (diff) |
Create Kubernetes cluster on GKE from k8s service
Diffstat (limited to 'app/controllers/projects/clusters_controller.rb')
-rw-r--r-- | app/controllers/projects/clusters_controller.rb | 102 |
1 files changed, 102 insertions, 0 deletions
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 |