|
| 1 | +/* |
| 2 | +Copyright 2024. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package metricstorage |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + |
| 22 | + corev1 "k8s.io/api/core/v1" |
| 23 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 24 | + |
| 25 | + "github.com/openstack-k8s-operators/lib-common/modules/common/tls" |
| 26 | + |
| 27 | + telemetryv1 "github.com/openstack-k8s-operators/telemetry-operator/api/v1beta1" |
| 28 | +) |
| 29 | + |
| 30 | +const ( |
| 31 | + host = "/etc/ksm" |
| 32 | + port = "tls_config.yaml" |
| 33 | + ca_secret = "" |
| 34 | + ca_key = "" |
| 35 | +) |
| 36 | + |
| 37 | +var ( |
| 38 | + TLSCertPath = fmt.Sprintf("/etc/pki/tls/certs/%s", tls.CertKey) |
| 39 | + TLSKeyPath = fmt.Sprintf("/etc/pki/tls/private/%s", tls.PrivateKey) |
| 40 | +) |
| 41 | + |
| 42 | +// KSMDeployment requests Deployment of kube-state-metrics |
| 43 | +func KSMTLSConfig( |
| 44 | + instance *telemetryv1.MetricStorage, |
| 45 | + labels map[string]string, |
| 46 | + clntCert bool, |
| 47 | +) *corev1.Secret { |
| 48 | + content := tlsBaseConfTemplate |
| 49 | + if clntCert { |
| 50 | + content = fmt.Sprintf("%s%s", content, fmt.Sprintf(tlsClntConfTemplate, TLSCertPath, TLSKeyPath)) |
| 51 | + } |
| 52 | + //if instance.Spec.KSMTLS.CaBundleSecretName != "" { |
| 53 | + // content = fmt.Sprintf("%s%s", content, fmt.Sprintf(tlsCaConfTemplate, tls.DownstreamTLSCABundlePath)) |
| 54 | + //} |
| 55 | + |
| 56 | + sec := &corev1.Secret{ |
| 57 | + ObjectMeta: metav1.ObjectMeta{ |
| 58 | + Name: fmt.Sprintf("%s-prometheus", instance.Name), |
| 59 | + Namespace: instance.Namespace, |
| 60 | + Labels: labels, |
| 61 | + }, |
| 62 | + Type: corev1.SecretTypeOpaque, |
| 63 | + Data: map[string][]byte{ |
| 64 | + tlsConfKey: []byte(content), |
| 65 | + }, |
| 66 | + } |
| 67 | + return sec |
| 68 | +} |
0 commit comments