Skip to content

Commit

Permalink
Remove empty objects from policy filter (#197)
Browse files Browse the repository at this point in the history
DId not find a way to do delete a file in post process. A argocd plugin complains about an empty yaml manifest.
  • Loading branch information
bastjan authored Aug 28, 2024
1 parent c398cfd commit 612c10c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 29 deletions.
7 changes: 0 additions & 7 deletions class/appuio-cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,3 @@ parameters:
- appuio-cloud/component/agent.jsonnet
input_type: jsonnet
output_path: appuio-cloud/01_agent/

commodore:
postprocess:
filters:
- type: jsonnet
filter: postprocess/disable-kyveno-policies.jsonnet
path: ${_instance}/
16 changes: 16 additions & 0 deletions component/common.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,23 @@ local agentFeatureEnabled(name) =
assert std.member(knownFeatures, name) : 'Unknown agent feature "%s"' % name;
std.member(params.agent_feature_set, name);

local disabledPolicies = std.prune(params.disable_kyverno_cluster_policies);

local removeDisabledPolicies = function(policies)
{
[p]: policies[p]
for p in std.filter(
function(pk)
local policy = policies[pk];
!std.isObject(policy) || policy.apiVersion != 'kyverno.io/v1' || policy.kind != 'ClusterPolicy' || std.length(std.find(policy.metadata.name, disabledPolicies)) == 0,
std.objectFields(policies)
)
};

{
// Remove disabled Kyverno policies
// Takes a dict with kubernetes resources and removes kyverno.io/v1.ClusterPolicy manifests that are disabled
RemoveDisabledPolicies: removeDisabledPolicies,
// AgentFeatureEnabled returns true if the given feature is enabled.
AgentFeatureEnabled: agentFeatureEnabled,
DefaultLabels: defaultLabels,
Expand Down
4 changes: 2 additions & 2 deletions component/namespace-policies.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,12 @@ local validateNamespaceMetadata = kyverno.ClusterPolicy('validate-namespace-meta
};

// Define outputs below
{
common.RemoveDisabledPolicies({
'01_appuio_ns_provisioner_role': appuioNsProvisionerRole + common.DefaultLabels,
'01_appuio_ns_provisioners_crb': appuioNsProvisionersRoleBinding + common.DefaultLabels,
'02_organization_namespaces': organizationNamespaces + common.DefaultLabels,
'02_organization_sa_namespaces': organizationSaNamespaces + common.DefaultLabels,
'02_organization_projects': organizationProjects + common.DefaultLabels,
'02_disallow_reserved_namespaces': disallowReservedNamespaces + common.DefaultLabels,
'02_validate_namespace_metadata': validateNamespaceMetadata + common.DefaultLabels,
}
})
4 changes: 2 additions & 2 deletions component/namespace-quota.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ local namespaceQuotaOverrides = [
];

// Define outputs below
{
common.RemoveDisabledPolicies({
[if !common.AgentFeatureEnabled('usage-profiles') then '12_namespace_quota_per_zone']: namespaceQuotaPolicy + common.DefaultLabels,
[if std.length(namespaceQuotaOverrides) > 0 then '13_namespace_quota_overrides']: namespaceQuotaOverrides,
}
})
4 changes: 2 additions & 2 deletions component/quota-limitrange.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ local generateQuotaLimitRangeInNsPolicy = kyverno.ClusterPolicy('quota-and-limit
};

// Define outputs below
{
common.RemoveDisabledPolicies({
[if !common.AgentFeatureEnabled('usage-profiles') then '11_generate_quota_limit_range_in_ns']: generateQuotaLimitRangeInNsPolicy + common.DefaultLabels,
}
})
4 changes: 2 additions & 2 deletions component/runonce-activedeadlineseconds.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ local policy =
},
};

{
common.RemoveDisabledPolicies({
'30_set_runonce_activedeadlineseconds': policy + common.DefaultLabels,
}
})
14 changes: 0 additions & 14 deletions postprocess/disable-kyveno-policies.jsonnet

This file was deleted.

0 comments on commit 612c10c

Please sign in to comment.