Commit d471bda2 authored by João Cunha's avatar João Cunha Committed by Kamil Trzciński

Remove Knative CRDs by group name instead of individually

- Tracks likst of api_groups instead of CRDs (much smaller)
- Adds kubectl command to fetch api resources by api group
- Adds kubectl command to delete api resources by api group
- Adds/Updates specs
parent 7a8553d1
......@@ -7,7 +7,7 @@ module Clusters
REPOSITORY = 'https://storage.googleapis.com/triggermesh-charts'
METRICS_CONFIG = 'https://storage.googleapis.com/triggermesh-charts/istio-metrics.yaml'
FETCH_IP_ADDRESS_DELAY = 30.seconds
API_RESOURCES_PATH = 'config/knative/api_resources.yml'
API_GROUPS_PATH = 'config/knative/api_groups.yml'
self.table_name = 'clusters_applications_knative'
......@@ -109,15 +109,15 @@ module Clusters
end
def delete_knative_and_istio_crds
api_resources.map do |crd|
Gitlab::Kubernetes::KubectlCmd.delete("--ignore-not-found", "crd", "#{crd}")
api_groups.map do |group|
Gitlab::Kubernetes::KubectlCmd.delete_crds_from_group(group)
end
end
# returns an array of CRDs to be postdelete since helm does not
# manage the CRDs it creates.
def api_resources
@api_resources ||= YAML.safe_load(File.read(Rails.root.join(API_RESOURCES_PATH)))
def api_groups
@api_groups ||= YAML.safe_load(File.read(Rails.root.join(API_GROUPS_PATH)))
end
def install_knative_metrics
......
---
- networking.istio.io
- rbac.istio.io
- authentication.istio.io
- config.istio.io
- networking.internal.knative.dev
- serving.knative.dev
- caching.internal.knative.dev
- autoscaling.internal.knative.dev
\ No newline at end of file
---
- meshpolicies.authentication.istio.io
- policies.authentication.istio.io
- adapters.config.istio.io
- apikeys.config.istio.io
- attributemanifests.config.istio.io
- authorizations.config.istio.io
- bypasses.config.istio.io
- podautoscalers.autoscaling.internal.knative.dev
- builds.build.knative.dev
- buildtemplates.build.knative.dev
- clusterbuildtemplates.build.knative.dev
- images.caching.internal.knative.dev
- certificates.networking.internal.knative.dev
- clusteringresses.networking.internal.knative.dev
- serverlessservices.networking.internal.knative.dev
- configurations.serving.knative.dev
- revisions.serving.knative.dev
- routes.serving.knative.dev
- services.serving.knative.dev
- checknothings.config.istio.io
- circonuses.config.istio.io
- deniers.config.istio.io
- edges.config.istio.io
- fluentds.config.istio.io
- handlers.config.istio.io
- httpapispecbindings.config.istio.io
- httpapispecs.config.istio.io
- instances.config.istio.io
- kubernetesenvs.config.istio.io
- kuberneteses.config.istio.io
- listcheckers.config.istio.io
- listentries.config.istio.io
- logentries.config.istio.io
- memquotas.config.istio.io
- metrics.config.istio.io
- noops.config.istio.io
- opas.config.istio.io
- prometheuses.config.istio.io
- quotas.config.istio.io
- quotaspecbindings.config.istio.io
- quotaspecs.config.istio.io
- rbacs.config.istio.io
- redisquotas.config.istio.io
- reportnothings.config.istio.io
- rules.config.istio.io
- servicecontrolreports.config.istio.io
- servicecontrols.config.istio.io
- signalfxs.config.istio.io
- solarwindses.config.istio.io
- stackdrivers.config.istio.io
- statsds.config.istio.io
- stdios.config.istio.io
- templates.config.istio.io
- tracespans.config.istio.io
- destinationrules.networking.istio.io
- envoyfilters.networking.istio.io
- gateways.networking.istio.io
- serviceentries.networking.istio.io
- virtualservices.networking.istio.io
- rbacconfigs.rbac.istio.io
- servicerolebindings.rbac.istio.io
- serviceroles.rbac.istio.io
- cloudwatches.config.istio.io
- clusterrbacconfigs.rbac.istio.io
- dogstatsds.config.istio.io
- ingresses.networking.internal.knative.dev
- sidecars.networking.istio.io
- zipkins.config.istio.io
......@@ -13,6 +13,16 @@ module Gitlab
%w(kubectl apply -f).concat([filename], args).shelljoin
end
def delete_crds_from_group(group)
api_resources_args = %w(-o name --api-group).push(group)
api_resources(*api_resources_args) + " | xargs " + delete('--ignore-not-found', 'crd')
end
def api_resources(*args)
%w(kubectl api-resources).concat(args).shelljoin
end
end
end
end
......
......@@ -45,4 +45,20 @@ describe Gitlab::Kubernetes::KubectlCmd do
end
end
end
describe '.api_resources' do
it 'constructs string properly' do
expected_command = 'kubectl api-resources -o name --api-group foo'
expect(described_class.api_resources("-o", "name", "--api-group", "foo")).to eq expected_command
end
end
describe '.delete_crds_from_group' do
it 'constructs string properly' do
expected_command = 'kubectl api-resources -o name --api-group foo | xargs kubectl delete --ignore-not-found crd'
expect(described_class.delete_crds_from_group("foo")).to eq expected_command
end
end
end
......@@ -161,18 +161,19 @@ describe Clusters::Applications::Knative do
end
it "initializes command with all necessary postdelete script" do
api_resources = YAML.safe_load(File.read(Rails.root.join(Clusters::Applications::Knative::API_RESOURCES_PATH)))
api_groups = YAML.safe_load(File.read(Rails.root.join(Clusters::Applications::Knative::API_GROUPS_PATH)))
remove_knative_istio_leftovers_script = [
"kubectl delete --ignore-not-found ns knative-serving",
"kubectl delete --ignore-not-found ns knative-build"
]
full_delete_commands_size = api_resources.size + remove_knative_istio_leftovers_script.size
full_delete_commands_size = api_groups.size + remove_knative_istio_leftovers_script.size
expect(subject.postdelete).to include(*remove_knative_istio_leftovers_script)
expect(subject.postdelete.size).to eq(full_delete_commands_size)
expect(subject.postdelete[2]).to eq("kubectl delete --ignore-not-found crd #{api_resources[0]}")
expect(subject.postdelete[2]).to eq("kubectl api-resources -o name --api-group #{api_groups[0]} | xargs kubectl delete --ignore-not-found crd")
expect(subject.postdelete[3]).to eq("kubectl api-resources -o name --api-group #{api_groups[1]} | xargs kubectl delete --ignore-not-found crd")
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment