Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: remove kube-rbac-proxy sidecar for metrics #2167

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 4 additions & 36 deletions assets/alertmanager-user-workload/alertmanager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ spec:
- --upstream=http://127.0.0.1:9093
- --tls-cert-file=/etc/tls/private/tls.crt
- --tls-private-key-file=/etc/tls/private/tls.key
- --client-ca-file=/etc/tls/client/client-ca.crt
- --tls-cipher-suites=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305
- --config-file=/etc/kube-rbac-proxy/config.yaml
- --logtostderr=true
Expand All @@ -54,6 +55,9 @@ spec:
- mountPath: /etc/kube-rbac-proxy
name: secret-alertmanager-kube-rbac-proxy
readOnly: true
- mountPath: /etc/tls/client
name: metrics-client-ca
readOnly: true
- args:
- --secure-listen-address=0.0.0.0:9092
- --upstream=http://127.0.0.1:9096
Expand Down Expand Up @@ -81,41 +85,6 @@ spec:
name: secret-alertmanager-kube-rbac-proxy-tenancy
- mountPath: /etc/tls/private
name: secret-alertmanager-user-workload-tls
- args:
- --secure-listen-address=0.0.0.0:9097
- --upstream=http://127.0.0.1:9093
- --config-file=/etc/kube-rbac-proxy/config.yaml
- --tls-cert-file=/etc/tls/private/tls.crt
- --tls-private-key-file=/etc/tls/private/tls.key
- --tls-cipher-suites=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305
- --client-ca-file=/etc/tls/client/client-ca.crt
- --logtostderr=true
- --allow-paths=/metrics
image: quay.io/brancz/kube-rbac-proxy:v0.15.0
name: kube-rbac-proxy-metric
ports:
- containerPort: 9097
name: metrics
resources:
requests:
cpu: 1m
memory: 15Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
terminationMessagePolicy: FallbackToLogsOnError
volumeMounts:
- mountPath: /etc/kube-rbac-proxy
name: secret-alertmanager-kube-rbac-proxy-metric
readOnly: true
- mountPath: /etc/tls/private
name: secret-alertmanager-user-workload-tls
readOnly: true
- mountPath: /etc/tls/client
name: metrics-client-ca
readOnly: true
- args:
- --insecure-listen-address=127.0.0.1:9096
- --upstream=http://127.0.0.1:9093
Expand Down Expand Up @@ -156,7 +125,6 @@ spec:
- alertmanager-user-workload-tls
- alertmanager-kube-rbac-proxy
- alertmanager-kube-rbac-proxy-tenancy
- alertmanager-kube-rbac-proxy-metric
securityContext:
fsGroup: 65534
runAsNonRoot: true
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion assets/alertmanager-user-workload/service-monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
endpoints:
- bearerTokenFile: ""
interval: 30s
port: metrics
port: web
scheme: https
tlsConfig:
caFile: /etc/prometheus/configmaps/serving-certs-ca-bundle/service-ca.crt
Expand Down
3 changes: 0 additions & 3 deletions assets/alertmanager-user-workload/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ spec:
- name: tenancy
port: 9092
targetPort: tenancy
- name: metrics
port: 9097
targetPort: metrics
selector:
app.kubernetes.io/component: alert-router
app.kubernetes.io/instance: user-workload
Expand Down
74 changes: 7 additions & 67 deletions jsonnet/components/alertmanager-user-workload.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ function(params)
port: 9092,
targetPort: 'tenancy',
},
{
name: 'metrics',
port: 9097,
targetPort: 'metrics',
},
],
type: 'ClusterIP',
},
Expand All @@ -63,7 +58,7 @@ function(params)
spec+: {
endpoints: [
{
port: 'metrics',
port: 'web',
interval: '30s',
scheme: 'https',
tlsConfig: {
Expand All @@ -80,7 +75,6 @@ function(params)
// In order for kube-rbac-proxy to perform a TokenReview and
// SubjectAccessReview for authN and authZ the alertmanager ServiceAccount
// requires the `create` action on both of these.

clusterRole: {
apiVersion: 'rbac.authorization.k8s.io/v1',
kind: 'ClusterRole',
Expand Down Expand Up @@ -180,12 +174,6 @@ function(params)
},
},

kubeRbacProxyMetricSecret: generateSecret.staticAuthSecret(cfg.namespace, cfg.commonLabels, 'alertmanager-kube-rbac-proxy-metric') + {
metadata+: {
labels: { 'app.kubernetes.io/name': 'alertmanager-' + cfg.name },
},
},

alertmanager+: {
spec+: {
securityContext: {
Expand All @@ -201,7 +189,6 @@ function(params)
'alertmanager-user-workload-tls',
$.kubeRbacProxySecret.metadata.name,
$.kubeRbacProxyTenancySecret.metadata.name,
$.kubeRbacProxyMetricSecret.metadata.name,
],
listenLocal: true,
resources: {
Expand Down Expand Up @@ -231,6 +218,7 @@ function(params)
'--upstream=http://127.0.0.1:9093',
'--tls-cert-file=/etc/tls/private/tls.crt',
'--tls-private-key-file=/etc/tls/private/tls.key',
'--client-ca-file=/etc/tls/client/client-ca.crt',
'--tls-cipher-suites=' + cfg.tlsCipherSuites,
'--config-file=/etc/kube-rbac-proxy/config.yaml',
'--logtostderr=true',
Expand All @@ -247,6 +235,11 @@ function(params)
name: 'secret-' + $.kubeRbacProxySecret.metadata.name,
readOnly: true,
},
{
mountPath: '/etc/tls/client',
name: 'metrics-client-ca',
readOnly: true,
},
],
securityContext: {
allowPrivilegeEscalation: false,
Expand Down Expand Up @@ -296,59 +289,6 @@ function(params)
},
},
},
{
// TODO: merge this metric proxy with tenancy proxy when the issue below is fixed:
// https://github.com/brancz/kube-rbac-proxy/issues/146
name: 'kube-rbac-proxy-metric',
image: cfg.kubeRbacProxyImage,
resources: {
requests: {
cpu: '1m',
memory: '15Mi',
},
},
ports: [
{
containerPort: 9097,
name: 'metrics',
},
],
args: [
'--secure-listen-address=0.0.0.0:9097',
'--upstream=http://127.0.0.1:9093',
'--config-file=/etc/kube-rbac-proxy/config.yaml',
'--tls-cert-file=/etc/tls/private/tls.crt',
'--tls-private-key-file=/etc/tls/private/tls.key',
'--tls-cipher-suites=' + cfg.tlsCipherSuites,
'--client-ca-file=/etc/tls/client/client-ca.crt',
'--logtostderr=true',
'--allow-paths=/metrics',
],
terminationMessagePolicy: 'FallbackToLogsOnError',
volumeMounts: [
{
mountPath: '/etc/kube-rbac-proxy',
name: 'secret-' + $.kubeRbacProxyMetricSecret.metadata.name,
readOnly: true,
},
{
mountPath: '/etc/tls/private',
name: 'secret-alertmanager-user-workload-tls',
readOnly: true,
},
{
mountPath: '/etc/tls/client',
name: 'metrics-client-ca',
readOnly: true,
},
],
securityContext: {
allowPrivilegeEscalation: false,
capabilities: {
drop: ['ALL'],
},
},
},
{
name: 'prom-label-proxy',
image: cfg.promLabelProxyImage,
Expand Down
12 changes: 8 additions & 4 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,12 +849,16 @@ func (c *Client) DeletePrometheusRuleByNamespaceAndName(ctx context.Context, nam
}

func (c *Client) DeleteSecret(ctx context.Context, s *v1.Secret) error {
err := c.kclient.CoreV1().Secrets(s.Namespace).Delete(ctx, s.GetName(), metav1.DeleteOptions{})
if apierrors.IsNotFound(err) {
return nil
return c.DeleteSecretByNamespaceAndName(ctx, s.GetNamespace(), s.GetName())
}

func (c *Client) DeleteSecretByNamespaceAndName(ctx context.Context, namespace, name string) error {
err := c.kclient.CoreV1().Secrets(namespace).Delete(ctx, name, metav1.DeleteOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("deleting Secret object failed: %w", err)
}

return err
return nil
}

// validatePrometheusResource is a helper method for ValidatePrometheus.
Expand Down
5 changes: 0 additions & 5 deletions pkg/manifests/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ var (
AlertmanagerUserWorkloadClusterRole = "alertmanager-user-workload/cluster-role.yaml"
AlertmanagerUserWorkloadRBACProxySecret = "alertmanager-user-workload/kube-rbac-proxy-secret.yaml"
AlertmanagerUserWorkloadRBACProxyTenancySecret = "alertmanager-user-workload/kube-rbac-proxy-tenancy-secret.yaml"
AlertmanagerUserWorkloadRBACProxyMetricSecret = "alertmanager-user-workload/kube-rbac-proxy-metric-secret.yaml"
AlertmanagerUserWorkloadTrustedCABundle = "alertmanager-user-workload/trusted-ca-bundle.yaml"
AlertmanagerUserWorkloadPodDisruptionBudget = "alertmanager-user-workload/pod-disruption-budget.yaml"
AlertmanagerUserWorkloadServiceMonitor = "alertmanager-user-workload/service-monitor.yaml"
Expand Down Expand Up @@ -717,10 +716,6 @@ func (f *Factory) AlertmanagerRBACProxyMetricSecret() (*v1.Secret, error) {
return f.NewSecret(f.assets.MustNewAssetReader(AlertmanagerRBACProxyMetricSecret))
}

func (f *Factory) AlertmanagerUserWorkloadRBACProxyMetricSecret() (*v1.Secret, error) {
return f.NewSecret(f.assets.MustNewAssetReader(AlertmanagerUserWorkloadRBACProxyMetricSecret))
}

func (f *Factory) AlertmanagerRoute() (*routev1.Route, error) {
return f.NewRoute(f.assets.MustNewAssetReader(AlertmanagerRoute))
}
Expand Down
19 changes: 2 additions & 17 deletions pkg/tasks/alertmanager_user_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,9 @@ func (t *AlertmanagerUserWorkloadTask) create(ctx context.Context) error {
return errors.Wrap(err, "creating Alertmanager User Workload RBAC proxy tenancy Secret failed")
}

rsm, err := t.factory.AlertmanagerUserWorkloadRBACProxyMetricSecret()
err = t.client.DeleteSecretByNamespaceAndName(ctx, "openshift-user-workload-monitoring", "alertmanager-kube-rbac-proxy-metric")
if err != nil {
return errors.Wrap(err, "initializing Alertmanager User Workload RBAC proxy metric Secret failed")
}

err = t.client.CreateIfNotExistSecret(ctx, rsm)
if err != nil {
return errors.Wrap(err, "creating Alertmanager User Workload RBAC proxy metric Secret failed")
return errors.Wrap(err, "deleting Alertmanager User Workload RBAC proxy metric Secret failed")
}

if t.config.UserWorkloadConfiguration.Alertmanager.Secrets != nil {
Expand Down Expand Up @@ -226,16 +221,6 @@ func (t *AlertmanagerUserWorkloadTask) destroy(ctx context.Context) error {
return errors.Wrap(err, "deleting Alertmanager User Workload RBAC proxy tenancy Secret failed")
}

rsm, err := t.factory.AlertmanagerUserWorkloadRBACProxyMetricSecret()
if err != nil {
return errors.Wrap(err, "initializing Alertmanager User Workload RBAC proxy metric Secret failed")
}

err = t.client.DeleteSecret(ctx, rsm)
if err != nil {
return errors.Wrap(err, "deleting Alertmanager User Workload RBAC proxy metric Secret failed")
}

cr, err := t.factory.AlertmanagerUserWorkloadClusterRole()
if err != nil {
return errors.Wrap(err, "initializing Alertmanager User Workload ClusterRole failed")
Expand Down