From 9583c49bb8df3caf9e7f5d21ebcbeaa1d6f10607 Mon Sep 17 00:00:00 2001 From: Brett Jones Date: Thu, 18 Mar 2021 15:15:12 -0500 Subject: [PATCH] maintenance --- config/manager/kustomization.yaml | 2 +- controllers/lokistack_controller.go | 20 +++++++++++++++++-- internal/manifests/build.go | 15 +++++++------- internal/manifests/config.go | 2 +- internal/manifests/distributor.go | 2 +- internal/manifests/ingester.go | 2 +- .../manifests/{ => internal}/config/build.go | 0 .../{ => internal}/config/loki-config.yaml | 0 .../{ => internal}/config/options.go | 0 internal/manifests/options.go | 9 +++++++++ internal/manifests/querier.go | 2 +- internal/manifests/query-frontend.go | 2 +- 12 files changed, 40 insertions(+), 16 deletions(-) rename internal/manifests/{ => internal}/config/build.go (100%) rename internal/manifests/{ => internal}/config/loki-config.yaml (100%) rename internal/manifests/{ => internal}/config/options.go (100%) create mode 100644 internal/manifests/options.go diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 1aa30aa666..1474d749f8 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -13,4 +13,4 @@ kind: Kustomization images: - name: controller newName: quay.io/blockloop/loki-operator - newTag: "1616076328" + newTag: "1616092265" diff --git a/controllers/lokistack_controller.go b/controllers/lokistack_controller.go index 0b12ac3301..7479a287cd 100644 --- a/controllers/lokistack_controller.go +++ b/controllers/lokistack_controller.go @@ -28,6 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" + apierrors "k8s.io/apimachinery/pkg/api/errors" lokiv1beta1 "github.com/ViaQ/loki-operator/api/v1beta1" ) @@ -56,11 +57,26 @@ type LokiStackReconciler struct { // For more details, check Reconcile and its Result here: // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.7.0/pkg/reconcile func (r *LokiStackReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - ll := log.WithValues("lokistack", req.NamespacedName) + ll := log.WithValues("lokistack", req.NamespacedName, "event", "create") + + var stack lokiv1beta1.LokiStack + if err := r.Get(ctx, req.NamespacedName, &stack); err != nil { + if apierrors.IsNotFound(err) { + // maybe the user deleted it before we could react? Either way this isn't an issue + ll.Error(err, "could not find the requested loki stack", "name", req.NamespacedName) + return ctrl.Result{}, nil + } + } + + // here we will translate the + opts := manifests.Options{ + Name: req.Name, + Namespace: req.Namespace, + } ll.Info("begin building manifests") - objects, err := manifests.BuildAll(req.Name, req.Namespace) + objects, err := manifests.BuildAll(opts) if err != nil { ll.Error(err, "failed to build manifests") return ctrl.Result{ diff --git a/internal/manifests/build.go b/internal/manifests/build.go index 899839e173..40a59b27c9 100644 --- a/internal/manifests/build.go +++ b/internal/manifests/build.go @@ -5,20 +5,19 @@ import ( ) // BuildAll builds all manifests required to run a Loki Stack -// TODO add options parameter to enable resource sizing, and other configurations -func BuildAll(stackName, namespace string) ([]client.Object, error) { +func BuildAll(opt Options) ([]client.Object, error) { res := make([]client.Object, 0) - cm, err := LokiConfigMap(stackName, namespace) + cm, err := LokiConfigMap(opt.Name, opt.Namespace) if err != nil { return nil, err } res = append(res, cm) - res = append(res, BuildDistributor(stackName)...) - res = append(res, BuildIngester(stackName)...) - res = append(res, BuildQuerier(stackName)...) - res = append(res, BuildQueryFrontend(stackName)...) - res = append(res, LokiGossipRingService(stackName)) + res = append(res, BuildDistributor(opt.Name)...) + res = append(res, BuildIngester(opt.Name)...) + res = append(res, BuildQuerier(opt.Name)...) + res = append(res, BuildQueryFrontend(opt.Name)...) + res = append(res, LokiGossipRingService(opt.Name)) return res, nil } diff --git a/internal/manifests/config.go b/internal/manifests/config.go index c50de0929a..0d370c8984 100644 --- a/internal/manifests/config.go +++ b/internal/manifests/config.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/ViaQ/loki-operator/internal/manifests/config" + "github.com/ViaQ/loki-operator/internal/manifests/internal/config" apps "k8s.io/api/apps/v1" core "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/internal/manifests/distributor.go b/internal/manifests/distributor.go index a1dfebb204..1c1fbe8d1d 100644 --- a/internal/manifests/distributor.go +++ b/internal/manifests/distributor.go @@ -4,7 +4,7 @@ import ( "fmt" "path" - "github.com/ViaQ/loki-operator/internal/manifests/config" + "github.com/ViaQ/loki-operator/internal/manifests/internal/config" apps "k8s.io/api/apps/v1" core "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/internal/manifests/ingester.go b/internal/manifests/ingester.go index 931949ea49..e062e197a0 100644 --- a/internal/manifests/ingester.go +++ b/internal/manifests/ingester.go @@ -4,7 +4,7 @@ import ( "fmt" "path" - "github.com/ViaQ/loki-operator/internal/manifests/config" + "github.com/ViaQ/loki-operator/internal/manifests/internal/config" apps "k8s.io/api/apps/v1" core "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/internal/manifests/config/build.go b/internal/manifests/internal/config/build.go similarity index 100% rename from internal/manifests/config/build.go rename to internal/manifests/internal/config/build.go diff --git a/internal/manifests/config/loki-config.yaml b/internal/manifests/internal/config/loki-config.yaml similarity index 100% rename from internal/manifests/config/loki-config.yaml rename to internal/manifests/internal/config/loki-config.yaml diff --git a/internal/manifests/config/options.go b/internal/manifests/internal/config/options.go similarity index 100% rename from internal/manifests/config/options.go rename to internal/manifests/internal/config/options.go diff --git a/internal/manifests/options.go b/internal/manifests/options.go new file mode 100644 index 0000000000..409c2bb0e7 --- /dev/null +++ b/internal/manifests/options.go @@ -0,0 +1,9 @@ +package manifests + +// Options is a set of options to use when building manifests such as resource sizes, etc. +// Most of this should be provided - either directly or indirectly - by the user. This will +// probably be converted from the CR. +type Options struct { + Name string + Namespace string +} diff --git a/internal/manifests/querier.go b/internal/manifests/querier.go index 2e2a5f10f1..77b11c07d5 100644 --- a/internal/manifests/querier.go +++ b/internal/manifests/querier.go @@ -4,7 +4,7 @@ import ( "fmt" "path" - "github.com/ViaQ/loki-operator/internal/manifests/config" + "github.com/ViaQ/loki-operator/internal/manifests/internal/config" apps "k8s.io/api/apps/v1" core "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/internal/manifests/query-frontend.go b/internal/manifests/query-frontend.go index fc7193ba89..db885bfe6b 100644 --- a/internal/manifests/query-frontend.go +++ b/internal/manifests/query-frontend.go @@ -4,7 +4,7 @@ import ( "fmt" "path" - "github.com/ViaQ/loki-operator/internal/manifests/config" + "github.com/ViaQ/loki-operator/internal/manifests/internal/config" apps "k8s.io/api/apps/v1" core "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"