Skip to content

Commit

Permalink
Label the kube resources that are created/updated by kubetruth
Browse files Browse the repository at this point in the history
  • Loading branch information
wr0ngway committed Feb 12, 2021
1 parent 23707a7 commit 35aeefc
Show file tree
Hide file tree
Showing 12 changed files with 1,261 additions and 287 deletions.
8 changes: 8 additions & 0 deletions lib/kubetruth/kubeapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def initialize(namespace: nil, token: nil, api_url: nil)
token_path = '/var/run/secrets/kubernetes.io/serviceaccount/token'

@namespace = namespace || File.read(namespace_path).chomp
@labels = {"app.kubernetes.io/managed-by" => "kubetruth"}

@auth_options = {}
if token
Expand Down Expand Up @@ -47,6 +48,7 @@ def ensure_namespace
ns = Kubeclient::Resource.new
ns.metadata = {}
ns.metadata.name = namespace
ns.metadata.labels = @labels
client.create_namespace(ns)
end
end
Expand All @@ -56,6 +58,8 @@ def get_config_map_names
end

def get_config_map(name)
# TODO: Make it so kubetruth skips over resources that it didn't create?
# e.g. client.get_config_map(name, namespace, label_selector: "app.kubernetes.io/managed-by=kubetruth") ?
resource = client.get_config_map(name, namespace)
resource.data.to_h
end
Expand All @@ -65,12 +69,14 @@ def create_config_map(name, data)
resource.metadata = {}
resource.metadata.name = name
resource.metadata.namespace = @namespace
resource.metadata.labels = @labels
resource.data = data
client.create_config_map(resource)
end

def update_config_map(name, data)
resource = client.get_config_map(name, namespace)
resource.metadata.labels = resource.metadata.labels.to_h.merge(@labels)
resource.data = data
client.update_config_map(resource)
end
Expand All @@ -94,12 +100,14 @@ def create_secret(name, data)
resource.metadata = {}
resource.metadata.name = name
resource.metadata.namespace = @namespace
resource.metadata.labels = @labels
resource.stringData = data
client.create_secret(resource)
end

def update_secret(name, data)
resource = client.get_secret(name, namespace)
resource.metadata.labels = resource.metadata.labels.to_h.merge(@labels)
resource.stringData = data
client.update_secret(resource)
end
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 35aeefc

Please sign in to comment.