-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[430] added clusters api #431
Merged
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8f7e5b2
[430] added clusters api
moklidia 9b14979
[430] added api to get namespace
moklidia 26efa8f
[430] added api to get namespace
moklidia 0034f3a
[430] updated routes and stubs
moklidia 70f7f1b
[430] changed routes, refactoring
moklidia 8e5c166
[430] added fixtures and updated controllers reponse
moklidia 0cd4c8f
[430] added new cluster state
moklidia 5893a19
[430] fixed state transition
moklidia 638a527
[430] checking of namespace creation failure, updated cluster name va…
moklidia cb0af72
[430] refactoring
moklidia 5d7c57f
[430] refactoring
moklidia d2ad4da
[430] fixed cluster name validation
moklidia 8c1395d
[430] Add manifest
zipofar 0589764
[430] added cluster serializer
moklidia a07b15e
[430] Refactor cluster creation
zipofar 6aa06d8
[430] Refactor cluster creation
zipofar be8cf02
[430] Add base_ingress_host
zipofar b86757b
[430] check for non-empty kubeconfig response
moklidia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,3 +70,5 @@ deployment: | |
subdomain: | ||
length_limit: 63 | ||
default_job_retry_count: 5 | ||
vcluster: | ||
max_creation_retry_count: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
core/app/controller_modules/uffizzi_core/api/cli/v1/projects/clusters_controller_module.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module UffizziCore::Api::Cli::V1::Projects::ClustersControllerModule | ||
private | ||
|
||
def update_show_trial_quota_exceeded_warning; end | ||
|
||
def stop_if_deployment_forbidden; end | ||
end |
46 changes: 46 additions & 0 deletions
46
core/app/controllers/uffizzi_core/api/cli/v1/projects/clusters_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
|
||
class UffizziCore::Api::Cli::V1::Projects::ClustersController < UffizziCore::Api::Cli::V1::Projects::ApplicationController | ||
include UffizziCore::Api::Cli::V1::Projects::ClustersControllerModule | ||
|
||
before_action :authorize_uffizzi_core_api_cli_v1_projects_clusters | ||
before_action :stop_if_deployment_forbidden, only: [:create] | ||
after_action :update_show_trial_quota_exceeded_warning, only: [:create, :destroy] | ||
|
||
def index | ||
clusters = resource_project.clusters.enabled | ||
|
||
respond_with clusters | ||
end | ||
|
||
def create | ||
cluster_form = UffizziCore::Api::Cli::V1::Cluster::CreateForm.new(cluster_params) | ||
cluster_form.project = resource_project | ||
cluster_form.deployed_by = current_user | ||
return respond_with cluster_form unless cluster_form.save | ||
|
||
UffizziCore::ClusterService.start_deploy(cluster_form) | ||
|
||
respond_with cluster_form | ||
end | ||
|
||
def show | ||
respond_with resource_cluster | ||
end | ||
|
||
def destroy | ||
resource_cluster.disable! | ||
|
||
head(:no_content) | ||
end | ||
|
||
private | ||
|
||
def resource_cluster | ||
@resource_cluster ||= resource_project.clusters.enabled.find_by!(name: params[:name]) | ||
end | ||
|
||
def cluster_params | ||
params.require(:cluster) | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
core/app/forms/uffizzi_core/api/cli/v1/cluster/create_form.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class UffizziCore::Api::Cli::V1::Cluster::CreateForm < UffizziCore::Cluster | ||
include UffizziCore::ApplicationForm | ||
|
||
permit :name, :manifest | ||
|
||
validate :check_manifest, if: -> { manifest.present? } | ||
|
||
private | ||
|
||
def check_manifest | ||
YAML.load_stream(manifest) | ||
rescue Psych::SyntaxError => e | ||
err = [e.problem, e.context].compact.join(' ') | ||
|
||
errors.add(:manifest, err) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class UffizziCore::Cluster::DeleteJob < UffizziCore::ApplicationJob | ||
sidekiq_options queue: :deployments, retry: 5 | ||
|
||
def perform(id) | ||
Rails.logger.info("DEPLOYMENT_PROCESS cluster_id=#{id} DeleteJob") | ||
|
||
cluster = UffizziCore::Cluster.find(id) | ||
UffizziCore::ControllerService.delete_namespace(cluster) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class UffizziCore::Cluster::DeployJob < UffizziCore::ApplicationJob | ||
sidekiq_options queue: :deployments, retry: 5 | ||
|
||
def perform(id) | ||
cluster = UffizziCore::Cluster.find(id) | ||
|
||
UffizziCore::ClusterService.deploy_cluster(cluster) | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
core/app/jobs/uffizzi_core/cluster/manage_deploying_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class UffizziCore::Cluster::ManageDeployingJob < UffizziCore::ApplicationJob | ||
sidekiq_options queue: :deployments, retry: 5 | ||
|
||
def perform(id, try = 1) | ||
cluster = UffizziCore::Cluster.find(id) | ||
|
||
UffizziCore::ClusterService.manage_deploying(cluster, try) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
module UffizziCore::Concerns::Models::Cluster | ||
extend ActiveSupport::Concern | ||
include UffizziCore::ClusterRepo | ||
|
||
included do | ||
include AASM | ||
|
||
self.table_name = UffizziCore.table_names[:clusters] | ||
|
||
belongs_to :project, class_name: UffizziCore::Project.name | ||
belongs_to :deployed_by, class_name: UffizziCore::User.name, foreign_key: :deployed_by_id, optional: true | ||
validates_uniqueness_of :name, conditions: -> { enabled } | ||
validates :name, presence: true, format: { with: /([A-Za-z0-9\-_]+)/ } | ||
|
||
aasm(:state) do | ||
state :deploying_namespace, initial: true | ||
state :failed_deploy_namespace | ||
state :deploying | ||
state :deployed | ||
state :failed | ||
state :disabled | ||
|
||
event :start_deploying do | ||
transitions from: [:deploying_namespace], to: :deploying | ||
end | ||
|
||
event :fail_deploy_namespace do | ||
transitions from: [:deploying_namespace], to: :failed_deploy_namespace | ||
end | ||
|
||
event :finish_deploy do | ||
transitions from: [:deploying], to: :deployed | ||
end | ||
|
||
event :fail do | ||
transitions from: [:deploying], to: :failed | ||
end | ||
|
||
event :disable, after: :after_disable do | ||
transitions from: [:fail_deploy_namespace, :deploying, :deployed, :failed], to: :disabled | ||
end | ||
end | ||
|
||
def after_disable | ||
UffizziCore::Cluster::DeleteJob.perform_async(id) | ||
end | ||
|
||
def namespace | ||
return name if name.present? | ||
|
||
"cluster-#{id}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class UffizziCore::Cluster < ApplicationRecord | ||
include UffizziCore::Concerns::Models::Cluster | ||
end |
19 changes: 19 additions & 0 deletions
19
core/app/policies/uffizzi_core/api/cli/v1/projects/clusters_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class UffizziCore::Api::Cli::V1::Projects::ClustersPolicy < UffizziCore::ApplicationPolicy | ||
def index? | ||
context.user_access_module.any_access_to_project?(context.user, context.project) | ||
end | ||
|
||
def show? | ||
context.user_access_module.any_access_to_project?(context.user, context.project) | ||
end | ||
|
||
def create? | ||
context.user_access_module.admin_or_developer_access_to_project?(context.user, context.project) | ||
end | ||
|
||
def destroy? | ||
context.user_access_module.admin_or_developer_access_to_project?(context.user, context.project) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
module UffizziCore::ClusterRepo | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
scope :deployed, -> { where(state: UffizziCore::Cluster::STATE_DEPLOYED) } | ||
scope :enabled, -> { where.not(state: UffizziCore::Cluster::STATE_DISABLED) } | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
core/app/serializers/uffizzi_core/api/cli/v1/projects/cluster_serializer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class UffizziCore::Api::Cli::V1::Projects::ClusterSerializer < UffizziCore::BaseSerializer | ||
type :cluster | ||
|
||
attributes :name, :state, :kubeconfig | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a user creates an empty cluster, will it be stuck in the
deploying_namespace
state?