From d8223468ae2ae061020cc26336c51dc93cc75571 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 6 Nov 2017 10:41:27 +0100 Subject: [PATCH] Add ingress application --- app/models/clusters/applications/ingress.rb | 32 +++++++++++++++++++ app/models/clusters/cluster.rb | 7 ++-- ...create_clusters_kubernetes_ingress_apps.rb | 21 ++++++++++++ db/schema.rb | 25 ++++++++------- 4 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 app/models/clusters/applications/ingress.rb create mode 100644 db/migrate/20171106101200_create_clusters_kubernetes_ingress_apps.rb diff --git a/app/models/clusters/applications/ingress.rb b/app/models/clusters/applications/ingress.rb new file mode 100644 index 00000000000..0554cf84ed7 --- /dev/null +++ b/app/models/clusters/applications/ingress.rb @@ -0,0 +1,32 @@ +module Clusters + module Applications + class Ingress < ActiveRecord::Base + self.table_name = 'clusters_applications_ingress' + + include ::Clusters::Concerns::ApplicationStatus + + belongs_to :cluster, class_name: 'Clusters::Cluster', foreign_key: :cluster_id + + validates :cluster, presence: true + + default_value_for :ingress_type, :nginx + default_value_for :version, :nginx + + enum ingress_type: { + nginx: 1 + } + + def self.application_name + self.to_s.demodulize.underscore + end + + def name + self.class.application_name + end + + def chart + 'stable/nginx-ingress' + end + end + end +end diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb index 7d0be3d3739..cfed9c52860 100644 --- a/app/models/clusters/cluster.rb +++ b/app/models/clusters/cluster.rb @@ -5,7 +5,8 @@ module Clusters self.table_name = 'clusters' APPLICATIONS = { - Applications::Helm.application_name => Applications::Helm + Applications::Helm.application_name => Applications::Helm, + Applications::Ingress.application_name => Applications::Ingress }.freeze belongs_to :user @@ -20,6 +21,7 @@ module Clusters has_one :platform_kubernetes, class_name: 'Clusters::Platforms::Kubernetes', autosave: true, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_one :application_helm, class_name: 'Clusters::Applications::Helm' + has_one :application_ingress, class_name: 'Clusters::Applications::Ingress' accepts_nested_attributes_for :provider_gcp, update_only: true accepts_nested_attributes_for :platform_kubernetes, update_only: true @@ -59,7 +61,8 @@ module Clusters def applications [ - application_helm || build_application_helm + application_helm || build_application_helm, + application_ingress || build_application_ingress ] end diff --git a/db/migrate/20171106101200_create_clusters_kubernetes_ingress_apps.rb b/db/migrate/20171106101200_create_clusters_kubernetes_ingress_apps.rb new file mode 100644 index 00000000000..21f48b1d1b4 --- /dev/null +++ b/db/migrate/20171106101200_create_clusters_kubernetes_ingress_apps.rb @@ -0,0 +1,21 @@ +class CreateClustersKubernetesIngressApps < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + create_table :clusters_applications_ingress do |t| + t.references :cluster, null: false, unique: true, foreign_key: { on_delete: :cascade } + + t.datetime_with_timezone :created_at, null: false + t.datetime_with_timezone :updated_at, null: false + + t.integer :status, null: false + t.integer :ingress_type, null: false + + t.string :version, null: false + t.string :cluster_ip + t.text :status_reason + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 548f4711339..2e5c98f2541 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171031100710) do +ActiveRecord::Schema.define(version: 20171106101200) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -464,9 +464,7 @@ ActiveRecord::Schema.define(version: 20171031100710) do create_table "cluster_platforms_kubernetes", force: :cascade do |t| t.integer "cluster_id", null: false - t.datetime_with_timezone "created_at", null: false - t.datetime_with_timezone "updated_at", null: false - t.text "api_url" + t.string "api_url" t.text "ca_cert" t.string "namespace" t.string "username" @@ -493,9 +491,6 @@ ActiveRecord::Schema.define(version: 20171031100710) do create_table "cluster_providers_gcp", force: :cascade do |t| t.integer "cluster_id", null: false t.integer "status" - t.integer "num_nodes", null: false - t.datetime_with_timezone "created_at", null: false - t.datetime_with_timezone "updated_at", null: false t.text "status_reason" t.string "gcp_project_id", null: false t.string "zone", null: false @@ -513,10 +508,6 @@ ActiveRecord::Schema.define(version: 20171031100710) do create_table "clusters", force: :cascade do |t| t.integer "user_id" - t.integer "provider_type" - t.integer "platform_type" - t.datetime_with_timezone "created_at", null: false - t.datetime_with_timezone "updated_at", null: false t.boolean "enabled", default: true t.string "name", null: false t.integer "provider_type" @@ -534,6 +525,17 @@ ActiveRecord::Schema.define(version: 20171031100710) do t.text "status_reason" end + create_table "clusters_applications_ingress", force: :cascade do |t| + t.integer "cluster_id", null: false + t.datetime_with_timezone "created_at", null: false + t.datetime_with_timezone "updated_at", null: false + t.integer "status", null: false + t.integer "ingress_type", null: false + t.string "version", null: false + t.string "cluster_ip" + t.text "status_reason" + end + create_table "container_repositories", force: :cascade do |t| t.integer "project_id", null: false t.string "name", null: false @@ -1888,6 +1890,7 @@ ActiveRecord::Schema.define(version: 20171031100710) do add_foreign_key "cluster_providers_gcp", "clusters", on_delete: :cascade add_foreign_key "clusters", "users", on_delete: :nullify add_foreign_key "clusters_applications_helm", "clusters", on_delete: :cascade + add_foreign_key "clusters_applications_ingress", "clusters", on_delete: :cascade add_foreign_key "container_repositories", "projects" add_foreign_key "deploy_keys_projects", "projects", name: "fk_58a901ca7e", on_delete: :cascade add_foreign_key "deployments", "projects", name: "fk_b9a3851b82", on_delete: :cascade -- GitLab