Fix local kind deployments (#101)

pull/4881/head
Periklis Tsirakidis 4 years ago committed by GitHub
parent 17c89f478f
commit c3e282e030
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      bundle/manifests/loki-operator.clusterserviceversion.yaml
  2. 2
      config/overlays/development/kustomization.yaml
  3. 3
      config/overlays/development/manager_image_pull_policy_patch.yaml
  4. 1
      config/overlays/openshift/manager_run_flags_patch.yaml
  5. 15
      controllers/lokistack_controller.go
  6. 80
      controllers/lokistack_controller_test.go
  7. 2
      hack/lokistack_dev.yaml
  8. 1
      internal/manifests/gateway.go
  9. 5
      internal/manifests/gateway_tenants.go
  10. 1
      internal/manifests/gateway_tenants_test.go
  11. 1
      internal/manifests/openshift/configure.go
  12. 1
      internal/manifests/options.go
  13. 9
      main.go

@ -581,6 +581,7 @@ spec:
containers: containers:
- args: - args:
- --with-lokistack-gateway - --with-lokistack-gateway
- --with-lokistack-gateway-route
- --with-cert-signing-service - --with-cert-signing-service
- --with-service-monitors - --with-service-monitors
- --with-tls-service-monitors - --with-tls-service-monitors

@ -19,4 +19,4 @@ commonLabels:
patchesStrategicMerge: patchesStrategicMerge:
- manager_related_image_patch.yaml - manager_related_image_patch.yaml
- manager_run_flags_patch.yaml - manager_image_pull_policy_patch.yaml

@ -7,5 +7,4 @@ spec:
spec: spec:
containers: containers:
- name: manager - name: manager
args: imagePullPolicy: Always
- "--with-lokistack-gateway"

@ -9,6 +9,7 @@ spec:
- name: manager - name: manager
args: args:
- "--with-lokistack-gateway" - "--with-lokistack-gateway"
- "--with-lokistack-gateway-route"
- "--with-cert-signing-service" - "--with-cert-signing-service"
- "--with-service-monitors" - "--with-service-monitors"
- "--with-tls-service-monitors" - "--with-tls-service-monitors"

@ -145,7 +145,7 @@ func (r *LokiStackReconciler) SetupWithManager(mgr manager.Manager) error {
} }
func (r *LokiStackReconciler) buildController(bld k8s.Builder) error { func (r *LokiStackReconciler) buildController(bld k8s.Builder) error {
return bld. bld = bld.
For(&lokiv1beta1.LokiStack{}, createOrUpdateOnlyPred). For(&lokiv1beta1.LokiStack{}, createOrUpdateOnlyPred).
Owns(&corev1.ConfigMap{}, updateOrDeleteOnlyPred). Owns(&corev1.ConfigMap{}, updateOrDeleteOnlyPred).
Owns(&corev1.ServiceAccount{}, updateOrDeleteOnlyPred). Owns(&corev1.ServiceAccount{}, updateOrDeleteOnlyPred).
@ -153,8 +153,13 @@ func (r *LokiStackReconciler) buildController(bld k8s.Builder) error {
Owns(&appsv1.Deployment{}, updateOrDeleteOnlyPred). Owns(&appsv1.Deployment{}, updateOrDeleteOnlyPred).
Owns(&appsv1.StatefulSet{}, updateOrDeleteOnlyPred). Owns(&appsv1.StatefulSet{}, updateOrDeleteOnlyPred).
Owns(&rbacv1.ClusterRole{}, updateOrDeleteOnlyPred). Owns(&rbacv1.ClusterRole{}, updateOrDeleteOnlyPred).
Owns(&rbacv1.ClusterRoleBinding{}, updateOrDeleteOnlyPred). Owns(&rbacv1.ClusterRoleBinding{}, updateOrDeleteOnlyPred)
Owns(&networkingv1.Ingress{}, updateOrDeleteOnlyPred).
Owns(&routev1.Route{}, updateOrDeleteOnlyPred). if r.Flags.EnableGatewayRoute {
Complete(r) bld = bld.Owns(&routev1.Route{}, updateOrDeleteOnlyPred)
} else {
bld = bld.Owns(&networkingv1.Ingress{}, updateOrDeleteOnlyPred)
}
return bld.Complete(r)
} }

@ -9,6 +9,7 @@ import (
"github.com/ViaQ/logerr/log" "github.com/ViaQ/logerr/log"
lokiv1beta1 "github.com/ViaQ/loki-operator/api/v1beta1" lokiv1beta1 "github.com/ViaQ/loki-operator/api/v1beta1"
"github.com/ViaQ/loki-operator/internal/external/k8s/k8sfakes" "github.com/ViaQ/loki-operator/internal/external/k8s/k8sfakes"
"github.com/ViaQ/loki-operator/internal/manifests"
routev1 "github.com/openshift/api/route/v1" routev1 "github.com/openshift/api/route/v1"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -70,65 +71,82 @@ func TestLokiStackController_RegistersCustomResourceForCreateOrUpdate(t *testing
} }
func TestLokiStackController_RegisterOwnedResourcesForUpdateOrDeleteOnly(t *testing.T) { func TestLokiStackController_RegisterOwnedResourcesForUpdateOrDeleteOnly(t *testing.T) {
b := &k8sfakes.FakeBuilder{}
k := &k8sfakes.FakeClient{} k := &k8sfakes.FakeClient{}
c := &LokiStackReconciler{Client: k, Scheme: scheme}
b.ForReturns(b)
b.OwnsReturns(b)
err := c.buildController(b)
require.NoError(t, err)
// Require Owns-Calls for all owned resources
require.Equal(t, 9, b.OwnsCallCount())
// Require owned resources // Require owned resources
type test struct { type test struct {
obj client.Object obj client.Object
pred builder.OwnsOption index int
flags manifests.FeatureFlags
pred builder.OwnsOption
} }
table := []test{ table := []test{
{ {
obj: &corev1.ConfigMap{}, obj: &corev1.ConfigMap{},
pred: updateOrDeleteOnlyPred, index: 0,
pred: updateOrDeleteOnlyPred,
}, },
{ {
obj: &corev1.ServiceAccount{}, obj: &corev1.ServiceAccount{},
pred: updateOrDeleteOnlyPred, index: 1,
pred: updateOrDeleteOnlyPred,
}, },
{ {
obj: &corev1.Service{}, obj: &corev1.Service{},
pred: updateOrDeleteOnlyPred, index: 2,
pred: updateOrDeleteOnlyPred,
}, },
{ {
obj: &appsv1.Deployment{}, obj: &appsv1.Deployment{},
pred: updateOrDeleteOnlyPred, index: 3,
pred: updateOrDeleteOnlyPred,
}, },
{ {
obj: &appsv1.StatefulSet{}, obj: &appsv1.StatefulSet{},
pred: updateOrDeleteOnlyPred, index: 4,
pred: updateOrDeleteOnlyPred,
}, },
{ {
obj: &rbacv1.ClusterRole{}, obj: &rbacv1.ClusterRole{},
pred: updateOrDeleteOnlyPred, index: 5,
pred: updateOrDeleteOnlyPred,
}, },
{ {
obj: &rbacv1.ClusterRoleBinding{}, obj: &rbacv1.ClusterRoleBinding{},
pred: updateOrDeleteOnlyPred, index: 6,
pred: updateOrDeleteOnlyPred,
}, },
{ {
obj: &networkingv1.Ingress{}, obj: &networkingv1.Ingress{},
index: 7,
flags: manifests.FeatureFlags{
EnableGatewayRoute: false,
},
pred: updateOrDeleteOnlyPred, pred: updateOrDeleteOnlyPred,
}, },
{ {
obj: &routev1.Route{}, obj: &routev1.Route{},
index: 7,
flags: manifests.FeatureFlags{
EnableGatewayRoute: true,
},
pred: updateOrDeleteOnlyPred, pred: updateOrDeleteOnlyPred,
}, },
} }
for i, tst := range table { for _, tst := range table {
b := &k8sfakes.FakeBuilder{}
b.ForReturns(b)
b.OwnsReturns(b)
c := &LokiStackReconciler{Client: k, Scheme: scheme, Flags: tst.flags}
err := c.buildController(b)
require.NoError(t, err)
// Require Owns-Calls for all owned resources
require.Equal(t, 8, b.OwnsCallCount())
// Require Owns-call options to have delete predicate only // Require Owns-call options to have delete predicate only
obj, opts := b.OwnsArgsForCall(i) obj, opts := b.OwnsArgsForCall(tst.index)
require.Equal(t, tst.obj, obj) require.Equal(t, tst.obj, obj)
require.Equal(t, tst.pred, opts[0]) require.Equal(t, tst.pred, opts[0])
} }

@ -8,4 +8,4 @@ spec:
storage: storage:
secret: secret:
name: test name: test
storageClassName: gp2 storageClassName: standard

@ -66,7 +66,6 @@ func BuildGateway(opts Options) ([]client.Object, error) {
// NewGatewayDeployment creates a deployment object for a lokiStack-gateway // NewGatewayDeployment creates a deployment object for a lokiStack-gateway
func NewGatewayDeployment(opts Options, sha1C string) *appsv1.Deployment { func NewGatewayDeployment(opts Options, sha1C string) *appsv1.Deployment {
podSpec := corev1.PodSpec{ podSpec := corev1.PodSpec{
ServiceAccountName: GatewayName(opts.Name),
Volumes: []corev1.Volume{ Volumes: []corev1.Volume{
{ {
Name: "rbac", Name: "rbac",

@ -18,6 +18,10 @@ import (
// tenant mode. Currently nothing is applied for modes static and dynamic. For mode openshift-logging // tenant mode. Currently nothing is applied for modes static and dynamic. For mode openshift-logging
// the tenant spec is filled with defaults for authentication and authorization. // the tenant spec is filled with defaults for authentication and authorization.
func ApplyGatewayDefaultOptions(opts *Options) error { func ApplyGatewayDefaultOptions(opts *Options) error {
if opts.Stack.Tenants == nil {
return nil
}
switch opts.Stack.Tenants.Mode { switch opts.Stack.Tenants.Mode {
case lokiv1beta1.Static, lokiv1beta1.Dynamic: case lokiv1beta1.Static, lokiv1beta1.Dynamic:
return nil // continue using user input return nil // continue using user input
@ -37,6 +41,7 @@ func ApplyGatewayDefaultOptions(opts *Options) error {
if err := mergo.Merge(&opts.OpenShiftOptions, &defaults, mergo.WithOverride); err != nil { if err := mergo.Merge(&opts.OpenShiftOptions, &defaults, mergo.WithOverride); err != nil {
return kverrors.Wrap(err, "failed to merge defaults for mode openshift logging") return kverrors.Wrap(err, "failed to merge defaults for mode openshift logging")
} }
} }
return nil return nil

@ -400,6 +400,7 @@ func TestConfigureDeploymentForMode(t *testing.T) {
Spec: appsv1.DeploymentSpec{ Spec: appsv1.DeploymentSpec{
Template: corev1.PodTemplateSpec{ Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{ Spec: corev1.PodSpec{
ServiceAccountName: "gateway",
Containers: []corev1.Container{ Containers: []corev1.Container{
{ {
Name: gatewayContainerName, Name: gatewayContainerName,

@ -92,6 +92,7 @@ func ConfigureGatewayDeployment(
gwContainer.Args = gwArgs gwContainer.Args = gwArgs
p := corev1.PodSpec{ p := corev1.PodSpec{
ServiceAccountName: d.GetName(),
Containers: []corev1.Container{ Containers: []corev1.Container{
*gwContainer, *gwContainer,
newOPAOpenShiftContainer(sercretVolumeName, tlsDir, certFile, keyFile, withTLS), newOPAOpenShiftContainer(sercretVolumeName, tlsDir, certFile, keyFile, withTLS),

@ -42,6 +42,7 @@ type FeatureFlags struct {
EnableServiceMonitors bool EnableServiceMonitors bool
EnableTLSServiceMonitorConfig bool EnableTLSServiceMonitorConfig bool
EnableGateway bool EnableGateway bool
EnableGatewayRoute bool
} }
// TenantSecrets for clientID, clientSecret and issuerCAPath for tenant's authentication. // TenantSecrets for clientID, clientSecret and issuerCAPath for tenant's authentication.

@ -61,6 +61,7 @@ func main() {
enableServiceMonitors bool enableServiceMonitors bool
enableTLSServiceMonitors bool enableTLSServiceMonitors bool
enableGateway bool enableGateway bool
enableGatewayRoute bool
) )
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
@ -75,6 +76,8 @@ func main() {
"Enables loading of a prometheus service monitor.") "Enables loading of a prometheus service monitor.")
flag.BoolVar(&enableGateway, "with-lokistack-gateway", false, flag.BoolVar(&enableGateway, "with-lokistack-gateway", false,
"Enables the manifest creation for the entire lokistack-gateway.") "Enables the manifest creation for the entire lokistack-gateway.")
flag.BoolVar(&enableGatewayRoute, "with-lokistack-gateway-route", false,
"Enables the usage of Route for the lokistack-gateway instead of Ingress (OCP Only!)")
flag.Parse() flag.Parse()
log.Init("loki-operator") log.Init("loki-operator")
@ -86,7 +89,10 @@ func main() {
if enableGateway { if enableGateway {
utilruntime.Must(configv1.AddToScheme(scheme)) utilruntime.Must(configv1.AddToScheme(scheme))
utilruntime.Must(routev1.AddToScheme(scheme))
if enableGatewayRoute {
utilruntime.Must(routev1.AddToScheme(scheme))
}
} }
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
@ -107,6 +113,7 @@ func main() {
EnableServiceMonitors: enableServiceMonitors, EnableServiceMonitors: enableServiceMonitors,
EnableTLSServiceMonitorConfig: enableTLSServiceMonitors, EnableTLSServiceMonitorConfig: enableTLSServiceMonitors,
EnableGateway: enableGateway, EnableGateway: enableGateway,
EnableGatewayRoute: enableGatewayRoute,
} }
if err = (&controllers.LokiStackReconciler{ if err = (&controllers.LokiStackReconciler{

Loading…
Cancel
Save