diff --git a/README.md b/README.md index 3f678fb..5cbecd3 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,11 @@ metadata: name: # DatabaseConfig name namespace: # DatabaseConfig namespace spec: - host: # host name for the database - token: # access token - clusterName: # generic compute cluster name - notebookPath: # path to the notebook + username: # username string + passwordSecretRef: # object reference to secret with password + name: # secret name + namespace: # secret namespace + key: # secret key --- apiVersion: finops.krateo.io/v1 kind: ScraperConfig @@ -50,7 +51,7 @@ spec: - Access to a Kubernetes v1.11.3+ cluster. ### Dependencies -There is the need to have an active Databricks cluster, with SQL warehouse and notebooks configured. Its login details must be placed in the database-config CR. +You need to install CrateDB in the cluster and configure the Krateo Database Webservice. ### Installation with HELM ```sh @@ -60,9 +61,8 @@ $ helm install finops-operator-scraper krateo/finops-operator-scraper ``` ### Configuration The database-config CR is required. -The deployment of the operator needs a secret for the repository, called `registry-credentials` in the namespace `finops`. -The scraper container is created in the namespace of the CR. The scraper container looks for a secret in the CR namespace called `registry-credentials-default` +The scraper container is created in the namespace of the CR. The scraper container looks for a secret in the CR namespace called `registry-credentials`, configurable in the HELM chart. ### Databricks token The Databricks token can be obtained through the dashboard UI. \ No newline at end of file diff --git a/config/crd/bases/finops.krateo.io_scraperconfigs.yaml b/config/crd/bases/finops.krateo.io_scraperconfigs.yaml index ae89531..fece7f9 100644 --- a/config/crd/bases/finops.krateo.io_scraperconfigs.yaml +++ b/config/crd/bases/finops.krateo.io_scraperconfigs.yaml @@ -183,6 +183,11 @@ spec: type: string type: object x-kubernetes-map-type: atomic + metricType: + default: cost + type: string + required: + - metricType type: object type: object served: true diff --git a/go.mod b/go.mod index dcb3bbb..ac9f5a7 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/krateoplatformops/finops-operator-scraper go 1.21 require ( - github.com/krateoplatformops/finops-data-types v0.0.0-20240822144053-7ce9ae5c26a7 + github.com/krateoplatformops/finops-data-types v0.0.0-20241114103324-d1c2aec150da github.com/onsi/ginkgo/v2 v2.14.0 github.com/onsi/gomega v1.30.0 k8s.io/apimachinery v0.29.0 diff --git a/go.sum b/go.sum index 106ffc5..1410398 100644 --- a/go.sum +++ b/go.sum @@ -68,6 +68,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/krateoplatformops/finops-data-types v0.0.0-20240822144053-7ce9ae5c26a7 h1:TDJf3NfxxjdENUc43Fpi/CDJ93PE3hSwCFA5+ZOg/74= github.com/krateoplatformops/finops-data-types v0.0.0-20240822144053-7ce9ae5c26a7/go.mod h1:sBjqLz0E1UCBP5Jnz6i1c9almnmgaf3eZ8Q+fANKzs4= +github.com/krateoplatformops/finops-data-types v0.0.0-20241114103324-d1c2aec150da h1:JbW9RC2eN7oTddgVdCqUI+nhgqbdpwZMQXVQXHvHY2w= +github.com/krateoplatformops/finops-data-types v0.0.0-20241114103324-d1c2aec150da/go.mod h1:sBjqLz0E1UCBP5Jnz6i1c9almnmgaf3eZ8Q+fANKzs4= github.com/krateoplatformops/finops-operator-exporter v0.0.0-20240714140455-0ba3f5de5546 h1:LZQI3kpAEF6uX0dfOo/N98rvyNSMXod6GxL666BvhzE= github.com/krateoplatformops/finops-operator-exporter v0.0.0-20240714140455-0ba3f5de5546/go.mod h1:PzdGRjH/V9BIbLEyaCu5+Kyjzw0yOTqtxTOUmcZRD8k= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= diff --git a/internal/utils/utils.go b/internal/utils/utils.go index f771857..facce81 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -13,8 +13,6 @@ import ( finopsv1 "github.com/krateoplatformops/finops-operator-scraper/api/v1" ) -var repository = strings.TrimSuffix(os.Getenv("REPO"), "/") - type ScraperConfigFile struct { DatabaseConfigRef finopsDataTypes.ObjectRef `yaml:"databaseConfigRef"` Exporter Exporter `yaml:"exporter"` @@ -24,6 +22,7 @@ type Exporter struct { Url string `yaml:"url"` PollingIntervalHours int `yaml:"pollingIntervalHours"` TableName string `yaml:"tableName"` + MetricType string `yaml:"metricType"` } func int32Ptr(i int32) *int32 { return &i } @@ -60,7 +59,7 @@ func GetGenericScraperDeployment(scraperConfig finopsv1.ScraperConfig) (*appsv1. Containers: []corev1.Container{ { Name: "scraper", - Image: repository + "/finops-prometheus-scraper-generic:latest", + Image: strings.TrimSuffix(os.Getenv("REGISTRY"), "/") + "/finops-prometheus-scraper-generic:latest", ImagePullPolicy: corev1.PullAlways, VolumeMounts: []corev1.VolumeMount{ { @@ -68,6 +67,12 @@ func GetGenericScraperDeployment(scraperConfig finopsv1.ScraperConfig) (*appsv1. MountPath: "/config", }, }, + Env: []corev1.EnvVar{ + { + Name: "URL_DB_WEBSERVICE", + Value: os.Getenv("URL_DB_WEBSERVICE"), + }, + }, }, }, Volumes: []corev1.Volume{ @@ -84,7 +89,7 @@ func GetGenericScraperDeployment(scraperConfig finopsv1.ScraperConfig) (*appsv1. }, ImagePullSecrets: []corev1.LocalObjectReference{ { - Name: "registry-credentials-default", + Name: os.Getenv("REGISTRY_CREDENTIALS"), }, }, }, @@ -98,6 +103,7 @@ func GetGenericScraperConfigMap(scraperConfig finopsv1.ScraperConfig) (*corev1.C databaseConfigRef := finopsDataTypes.ObjectRef{} exporter := Exporter{} + exporter.MetricType = scraperConfig.Status.MetricType exporter.Url = scraperConfig.Spec.Url exporter.PollingIntervalHours = scraperConfig.Spec.PollingIntervalHours exporter.TableName = scraperConfig.Spec.TableName