Class: LanguageOperator::CLI::Commands::Install

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/language_operator/cli/commands/install.rb

Overview

Install, upgrade, and uninstall commands for the language-operator

Constant Summary collapse

HELM_REPO_NAME =
'language-operator'
HELM_REPO_URL =
'https://language-operator.github.io/charts'
CHART_NAME =
'language-operator/language-operator'
RELEASE_NAME =
'language-operator'
DEFAULT_NAMESPACE =
'language-operator'
LONG_DESCRIPTIONS =

Long descriptions for commands

{
  install: <<-DESC,
  upgrade: <<-DESC,
  uninstall: <<-DESC
    Completely uninstall the language-operator from your Kubernetes cluster.

    This will:
    1. Delete all custom resources (agents, tools, models, personas, clusters)
    2. Uninstall the operator using Helm
    3. Remove all CRDs (CustomResourceDefinitions)

    WARNING: This will completely remove all language-operator resources from the cluster.

    Examples:
      # Complete uninstall with confirmation
      langop uninstall

      # Force uninstall without confirmation
      langop uninstall --force

      # Uninstall from specific namespace
      langop uninstall --namespace my-namespace
  DESC
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::UxHelper

#box, #highlight_ruby_code, #logo, #pastel, #prompt, #spinner, #table

Class Method Details

.long_desc_for(command) ⇒ Object

Helper method to get long descriptions for commands



86
87
88
# File 'lib/language_operator/cli/commands/install.rb', line 86

def self.long_desc_for(command)
  LONG_DESCRIPTIONS[command]
end

Instance Method Details

#installObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/language_operator/cli/commands/install.rb', line 120

def install
  handle_command_error('install') do
    # Check if helm is available
    check_helm_installed!

    # Check if operator is already installed
    if operator_installed? && !options[:dry_run]
      Formatters::ProgressFormatter.warn('Language operator is already installed')
      puts
      puts 'To upgrade, use:'
      puts '  langop upgrade'
      return
    end

    namespace = options[:namespace]

    # Interactive configuration unless non-interactive mode or custom values provided
    unless options[:non_interactive] || options[:values]
      (title: 'language operator installer')
      puts 'This installer will help you configure the Language Operator for your cluster.'
      puts

      config = collect_interactive_configuration
      values_file = generate_values_file(config)
      # Create a mutable copy of options to avoid frozen hash error
      @options = options.dup
      @options[:values] = values_file
    end

    # Add Helm repository
    add_helm_repo unless (@options || options)[:dry_run]

    # Build helm install command (use @options if we created a mutable copy)
    cmd = build_helm_command('install', namespace)

    # Execute helm install
    if (@options || options)[:dry_run]
      puts 'Dry run - would execute:'
      puts "  #{cmd}"
      puts
      success, output = run_helm_command(cmd)
      puts output
    else
      Formatters::ProgressFormatter.with_spinner('Installing language-operator') do
        success, output = run_helm_command(cmd)
        raise "Helm install failed: #{output}" unless success
      end

      # Post-installation verification
      verify_installation(config)
    end
  end
end

#uninstallObject



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/language_operator/cli/commands/install.rb', line 263

def uninstall
  handle_command_error('uninstall') do
    # Check if helm is available
    check_helm_installed!

    # Check if operator is installed but proceed with cleanup regardless

    namespace = options[:namespace]

    # Confirm deletion unless --force
    unless options[:force]
      puts 'This will completely uninstall the language-operator from your cluster:'
      puts
      puts '  - The language-operator Helm release'
      puts '  - All existing clusters, agents, models, tools and personas'
      puts '  - All organization namespaces and their resources'
      puts '  - Persistent volumes (ClickHouse, PostgreSQL data)'
      puts '  - Cluster-scoped resources (RBAC, webhooks, CRDs)'
      puts "  - The operator namespace (#{namespace})"
      puts
      puts "#{pastel.bold.red('WARNING')}: #{pastel.white.bold('This action cannot be undone!')}"
      puts
      return unless CLI::Helpers::UserPrompts.confirm('Continue with complete uninstall?')
    end

    # Step 1: Delete all custom resources
    delete_all_custom_resources

    # Step 2: Delete organization namespaces
    delete_organization_namespaces

    # Step 3: Uninstall Helm release if it exists
    if operator_installed?
      cmd = "helm uninstall #{RELEASE_NAME} --namespace #{namespace}"

      Formatters::ProgressFormatter.with_spinner('Uninstalling language-operator Helm release') do
        success, output = run_helm_command(cmd)
        raise "Helm uninstall failed: #{output}" unless success
      end
    end

    # Step 4: Delete PVCs
    delete_persistent_volumes

    # Step 5: Clean up cluster-scoped resources
    delete_cluster_scoped_resources

    # Step 6: Delete CRDs
    delete_language_operator_crds

    # Step 7: Delete the operator namespace
    delete_operator_namespace(namespace)
  end
end

#upgradeObject



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/language_operator/cli/commands/install.rb', line 199

def upgrade
  handle_command_error('upgrade') do
    # Check if helm is available
    check_helm_installed!

    # Check if operator is installed
    unless operator_installed?
      Formatters::ProgressFormatter.error('Language operator is not installed')
      puts
      puts 'To install, use:'
      puts '  langop install'
      exit 1
    end

    namespace = options[:namespace]

    # Add/Update Helm repository  
    add_helm_repo unless options[:dry_run]

    # Build helm upgrade command
    cmd = build_helm_command('upgrade', namespace)

    # Execute helm upgrade
    if options[:dry_run]
      puts 'Dry run - would execute:'
      puts "  #{cmd}"
      puts
      success, output = run_helm_command(cmd)
      puts output
    else
      Formatters::ProgressFormatter.with_spinner('Upgrading language-operator') do
        success, output = run_helm_command(cmd)
        raise "Helm upgrade failed: #{output}" unless success
      end

      # Restart the language-operator deployment to ensure new version is running
      restart_language_operator_deployment(namespace)
    end
  end
end