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

Mage crds #716

Merged
merged 3 commits into from
Jan 14, 2025
Merged
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
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ go 1.21

require (
github.com/bwplotka/mimic v0.2.1-0.20230303101552-f705cca2f4a4
github.com/go-kit/log v0.2.1
github.com/google/go-jsonnet v0.20.0
github.com/observatorium/api v0.1.3-0.20230711132510-96e8799ade44
github.com/observatorium/observatorium v0.0.0-20240202123905-a8245e065e5c
github.com/observatorium/up v0.0.0-20240109115132-3a34c4c4fa24
github.com/openshift/api v3.9.0+incompatible
github.com/philipgough/mimic v0.0.0-20250112154247-23e51fe097ae
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.70.0
github.com/pyrra-dev/pyrra v0.7.2
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.29.0
k8s.io/apiextensions-apiserver v0.29.0
k8s.io/apimachinery v0.29.0
)

Expand All @@ -27,7 +30,6 @@ require (
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
Expand Down Expand Up @@ -73,7 +75,6 @@ require (
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiextensions-apiserver v0.29.0 // indirect
k8s.io/client-go v0.29.0 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20240105020646-a37d4de58910 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,8 @@ github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/philipgough/mimic v0.0.0-20250112154247-23e51fe097ae h1:gVta72edrfZlBSJZQFtUHuhwUWsruo/xGYuYw0CFsXs=
github.com/philipgough/mimic v0.0.0-20250112154247-23e51fe097ae/go.mod h1:77oIx2ozDojDKUhCVOw4KHTVwl7fsiN/NZ6q+0MLJwI=
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
Expand Down
74 changes: 74 additions & 0 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package main

import (
"fmt"
"net/http"
"os"

"github.com/go-kit/log"
"github.com/observatorium/observatorium/configuration_go/kubegen/openshift"
templatev1 "github.com/openshift/api/template/v1"
"github.com/philipgough/mimic"
"github.com/philipgough/mimic/encoding"

v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/yaml"
)

const (
templatePath = "resources"
templateServicesPath = "services"
)

// CRDS Generates the CRDs for the Thanos operator.
// This is synced from the latest upstream main at:
// https://github.com/thanos-community/thanos-operator/tree/main/config/crd/bases
func CRDS() error {
const (
templateDir = "crds"
base = "https://raw.githubusercontent.com/thanos-community/thanos-operator/refs/heads/main/config/crd/bases/monitoring.thanos.io_"
)

const (
compact = "thanoscompacts.yaml"
queries = "thanosqueries.yaml"
receivers = "thanosreceives.yaml"
rulers = "thanosrulers.yaml"
stores = "thanosstores.yaml"
)

gen := &mimic.Generator{}
gen = gen.With(templatePath, templateServicesPath, templateDir)
gen.Logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout))

var objs []runtime.Object
for _, component := range []string{compact, queries, receivers, rulers, stores} {
manifest := base + component
resp, err := http.Get(manifest)
if err != nil {
return fmt.Errorf("failed to fetch %s: %w", manifest, err)
}

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to fetch %s: %s", manifest, resp.Status)
}

var obj v1.CustomResourceDefinition
decoder := yaml.NewYAMLOrJSONDecoder(resp.Body, 100000)
err = decoder.Decode(&obj)
if err != nil {
return fmt.Errorf("failed to decode %s: %w", manifest, err)
}

objs = append(objs, &obj)
resp.Body.Close()
}

template := openshift.WrapInTemplate(objs, metav1.ObjectMeta{Name: "thanos-operator"}, []templatev1.Parameter{})
encoder := encoding.GhodssYAML(template)
gen.Add("thanos-operator.yaml", encoder)
gen.Generate()
return nil
}
Loading
Loading