Skip to content

Commit

Permalink
Merge pull request #943 from openshift-cherrypick-robot/cherry-pick-9…
Browse files Browse the repository at this point in the history
…42-to-release-5.5

[release-5.5] Make the operator tolerate missing console CRDs in OCP 4.12+
  • Loading branch information
openshift-merge-robot committed Sep 20, 2022
2 parents f3b445f + be4107f commit b73db7b
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 27 deletions.
2 changes: 1 addition & 1 deletion controllers/logging/elasticsearch_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *ElasticsearchReconciler) Reconcile(ctx context.Context, request ctrl.Re
r.Log.Info("Flushing nodes", "objectKey", request.NamespacedName)
elasticsearch.FlushNodes(request.NamespacedName.Name, request.NamespacedName.Namespace)
elasticsearch.RemoveDashboardConfigMap(r.Log, r.Client)
if err := console.DeleteKibanaConsoleLink(context.TODO(), r.Client); err != nil {
if err := console.DeleteKibanaConsoleLink(context.TODO(), r.Client, r.Log); err != nil {
r.Log.Error(err, "failed to delete consolelink")
}
return ctrl.Result{}, nil
Expand Down
2 changes: 1 addition & 1 deletion controllers/logging/kibana_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (r *KibanaReconciler) Reconcile(ctx context.Context, request ctrl.Request)
if errors.IsNotFound(err) {
// the CR no longer exists, since it will be cleaned up by the scheduler we don't want to trigger an event for it
unregisterKibanaNamespacedName(r.Log, request)
if err := console.DeleteConsoleExternalLogLink(ctx, r.Client); err != nil {
if err := console.DeleteConsoleExternalLogLink(ctx, r.Client, r.Log); err != nil {
r.Log.Error(err, "failed to delete consoleexternalloglink")
}
return reconcile.Result{}, nil
Expand Down
16 changes: 0 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,6 @@ github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2cUuW7uA/OeU=
github.com/googleapis/gnostic v0.5.5/go.mod h1:7+EbHbldMins07ALC74bsA81Ovc97DwqyJO1AENw9kA=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
Expand Down Expand Up @@ -392,8 +390,6 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/openshift/api v0.0.0-20220124143425-d74727069f6f h1:iOTv1WudhVm2UsoST+L+ZrA5A9w57h9vmQsdlBuqG6g=
github.com/openshift/api v0.0.0-20220124143425-d74727069f6f/go.mod h1:F/eU6jgr6Q2VhMu1mSpMmygxAELd7+BUxs3NHZ25jV4=
github.com/openshift/api v0.0.0-20220712151050-2647eb31dee7 h1:zjlaMHqzNrrm8bnltBnrKLwxALoLAH/8UAkBEESrEOg=
github.com/openshift/api v0.0.0-20220712151050-2647eb31dee7/go.mod h1:LEnw1IVscIxyDnltE3Wi7bQb/QzIM8BfPNKoGA1Qlxw=
github.com/openshift/build-machinery-go v0.0.0-20211213093930-7e33a7eb4ce3/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE=
Expand Down Expand Up @@ -488,7 +484,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4=
Expand Down Expand Up @@ -627,7 +622,6 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
Expand Down Expand Up @@ -720,7 +714,6 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down Expand Up @@ -805,7 +798,6 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff/go.mod h1:YD9qOF0M9xpSpdWTBbzEl5e/RnCefISl8E5Noe10jFM=
golang.org/x/tools v0.1.10-0.20220218145154-897bd77cd717/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down Expand Up @@ -965,36 +957,30 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.23.0/go.mod h1:8wmDdLBHBNxtOIytwLstXt5E9PddnZb0GaMcqsvDBpg=
k8s.io/api v0.24.0/go.mod h1:5Jl90IUrJHUJYEMANRURMiVvJ0g7Ax7r3R1bqO8zx8I=
k8s.io/api v0.24.3 h1:tt55QEmKd6L2k5DP6G/ZzdMQKvG5ro4H4teClqm0sTY=
k8s.io/api v0.24.3/go.mod h1:elGR/XSZrS7z7cSZPzVWaycpJuGIw57j9b95/1PdJNI=
k8s.io/apiextensions-apiserver v0.24.0 h1:JfgFqbA8gKJ/uDT++feAqk9jBIwNnL9YGdQvaI9DLtY=
k8s.io/apiextensions-apiserver v0.24.0/go.mod h1:iuVe4aEpe6827lvO6yWQVxiPSpPoSKVjkq+MIdg84cM=
k8s.io/apimachinery v0.23.0/go.mod h1:fFCTTBKvKcwTPFzjlcxp91uPFZr+JA0FubU4fLzzFYc=
k8s.io/apimachinery v0.24.0/go.mod h1:82Bi4sCzVBdpYjyI4jY6aHX+YCUchUIrZrXKedjd2UM=
k8s.io/apimachinery v0.24.3 h1:hrFiNSA2cBZqllakVYyH/VyEh4B581bQRmqATJSeQTg=
k8s.io/apimachinery v0.24.3/go.mod h1:82Bi4sCzVBdpYjyI4jY6aHX+YCUchUIrZrXKedjd2UM=
k8s.io/apiserver v0.24.0/go.mod h1:WFx2yiOMawnogNToVvUYT9nn1jaIkMKj41ZYCVycsBA=
k8s.io/client-go v0.24.0/go.mod h1:VFPQET+cAFpYxh6Bq6f4xyMY80G6jKKktU6G0m00VDw=
k8s.io/client-go v0.24.3 h1:Nl1840+6p4JqkFWEW2LnMKU667BUxw03REfLAVhuKQY=
k8s.io/client-go v0.24.3/go.mod h1:AAovolf5Z9bY1wIg2FZ8LPQlEdKHjLI7ZD4rw920BJw=
k8s.io/code-generator v0.23.0/go.mod h1:vQvOhDXhuzqiVfM/YHp+dmg10WDZCchJVObc9MvowsE=
k8s.io/code-generator v0.24.0/go.mod h1:dpVhs00hTuTdTY6jvVxvTFCk6gSMrtfRydbhZwHI15w=
k8s.io/component-base v0.24.0 h1:h5jieHZQoHrY/lHG+HyrSbJeyfuitheBvqvKwKHVC0g=
k8s.io/component-base v0.24.0/go.mod h1:Dgazgon0i7KYUsS8krG8muGiMVtUZxG037l1MKyXgrA=
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/gengo v0.0.0-20211129171323-c02415ce4185/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
k8s.io/klog/v2 v2.30.0/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/klog/v2 v2.60.1 h1:VW25q3bZx9uE3vvdL6M8ezOX79vA2Aq1nEWLqNQclHc=
k8s.io/klog/v2 v2.60.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65/go.mod h1:sX9MT8g7NVZM5lVL/j8QyCCJe8YSMW30QvGZWaCIDIk=
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 h1:Gii5eqf+GmIEwGNKQYQClCayuJCe2/4fZUvF7VG99sU=
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42/go.mod h1:Z/45zLw8lUo4wdiUkI+v/ImEGAvu3WatcZl3lPMR4Rk=
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20220713171938-56c0de1e6f5e h1:W1yba+Bpkwb5BatGKZALQ1yylhwnuD6CkYmrTibyLDM=
k8s.io/utils v0.0.0-20220713171938-56c0de1e6f5e/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
Expand All @@ -1004,11 +990,9 @@ rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.30/go.mod h1:fEO7lRTdivWO2qYVCVG7dEADOMo/MLDCVr8So2g88Uw=
sigs.k8s.io/controller-runtime v0.12.1 h1:4BJY01xe9zKQti8oRjj/NeHKRXthf1YkYJAgLONFFoI=
sigs.k8s.io/controller-runtime v0.12.1/go.mod h1:BKhxlA4l7FPK4AQcsuL4X6vZeWnKDXez/vp1Y8dxTU0=
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6/go.mod h1:p4QtZmO4uMYipTQNzagwnNoseA6OxSUutVw05NhYDRs=
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 h1:kDi4JBNAsJWfz1aEXhO8Jg87JJaPNLh5tIzYHgStQ9Y=
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2/go.mod h1:B+TnT182UBxE84DiCz4CVE26eOSDAeYCpfDnC2kdKMY=
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 h1:bKCqE9GvQ5tiVHn5rfn1r+yao3aLQEaLzkkmAkf+A6Y=
sigs.k8s.io/structured-merge-diff/v4 v4.2.1/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
Expand Down
62 changes: 62 additions & 0 deletions hack/cvo-unmanage-console.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
apiVersion: config.openshift.io/v1
kind: ClusterVersion
metadata:
namespace: openshift-cluster-version
name: version
spec:
overrides:
- kind: Deployment
name: console-operator
namespace: openshift-console-operator
unmanaged: true
group: apps
- kind: ClusterRole
name: console-operator
namespace: ""
unmanaged: true
group: rbac.authorization.k8s.io
- kind: CustomResourceDefinition
name: consoleclidownloads.console.openshift.io
namespace: ""
unmanaged: true
group: apiextensions.k8s.io
- kind: CustomResourceDefinition
name: consoleexternalloglinks.console.openshift.io
namespace: ""
unmanaged: true
group: apiextensions.k8s.io
- kind: CustomResourceDefinition
name: consolelinks.console.openshift.io
namespace: ""
unmanaged: true
group: apiextensions.k8s.io
- kind: CustomResourceDefinition
name: consolenotifications.console.openshift.io
namespace: ""
unmanaged: true
group: apiextensions.k8s.io
- kind: CustomResourceDefinition
name: consoleplugins.console.openshift.io
namespace: ""
unmanaged: true
group: apiextensions.k8s.io
- kind: CustomResourceDefinition
name: consolequickstarts.console.openshift.io
namespace: ""
unmanaged: true
group: apiextensions.k8s.io
- kind: CustomResourceDefinition
name: consoles.config.openshift.io
namespace: ""
unmanaged: true
group: apiextensions.k8s.io
- kind: CustomResourceDefinition
name: consoles.operator.openshift.io
namespace: ""
unmanaged: true
group: apiextensions.k8s.io
- kind: CustomResourceDefinition
name: consoleyamlsamples.console.openshift.io
namespace: ""
unmanaged: true
group: apiextensions.k8s.io
34 changes: 31 additions & 3 deletions internal/kibana/kibana_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
loggingv1 "github.com/openshift/elasticsearch-operator/apis/logging/v1"
"github.com/openshift/elasticsearch-operator/internal/constants"
"github.com/openshift/elasticsearch-operator/internal/elasticsearch/esclient"
"github.com/openshift/elasticsearch-operator/internal/manifests/console"
"github.com/openshift/elasticsearch-operator/test/helpers"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -168,6 +169,26 @@ var _ = Describe("Reconciling", func() {
},
}

consoleExternalLogLink = &consolev1.ConsoleExternalLogLink{
TypeMeta: metav1.TypeMeta{
Kind: "ConsoleExternalLogLink",
APIVersion: "console.openshift.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: console.ExternalLogLinkName,
ResourceVersion: "1",
Labels: map[string]string{
"component": "support",
"logging-infra": "support",
"provider": "openshift",
},
},
Spec: consolev1.ConsoleExternalLogLinkSpec{
Text: "Show in Kibana",
HrefTemplate: "https:///app/kibana#/discover?_g=(time:(from:now-1w,mode:relative,to:now))&_a=(columns:!(kubernetes.container_name,message),query:(query_string:(analyze_wildcard:!t,query:'kubernetes.pod_name:\"${resourceName}\" AND kubernetes.namespace_name:\"${resourceNamespace}\" AND kubernetes.container_name.raw:\"${containerName}\"')),sort:!('@timestamp',desc))",
},
}

fakeResponses = map[string]helpers.FakeElasticsearchResponses{
"_cat/indices/.kibana?format=json": {
{
Expand Down Expand Up @@ -207,11 +228,18 @@ var _ = Describe("Reconciling", func() {
Expect(Reconcile(logger, cluster, client, esClient, proxy, false, metav1.OwnerReference{})).Should(Succeed())

key := types.NamespacedName{Name: KibanaConsoleLinkName}
got := &consolev1.ConsoleLink{}
cl := &consolev1.ConsoleLink{}

err := client.Get(context.TODO(), key, cl)
Expect(err).To(BeNil())
Expect(cl).To(Equal(consoleLink))

key = types.NamespacedName{Name: console.ExternalLogLinkName}
cel := &consolev1.ConsoleExternalLogLink{}

err := client.Get(context.TODO(), key, got)
err = client.Get(context.TODO(), key, cel)
Expect(err).To(BeNil())
Expect(got).To(Equal(consoleLink))
Expect(cel).To(Equal(consoleExternalLogLink))
})
})

Expand Down
10 changes: 10 additions & 0 deletions internal/kibana/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func (clusterRequest *KibanaRequest) createOrUpdateKibanaRoute() error {
func (clusterRequest *KibanaRequest) createOrUpdateKibanaConsoleLink() error {
cluster := clusterRequest.cluster

if !console.ConsoleLinkEnabled(clusterRequest.client) {
clusterRequest.log.Info("ConsoleLink kind is not found, skipping console link creation")
return nil
}

kibanaURL, err := clusterRequest.GetRouteURL("kibana")
if err != nil {
return kverrors.Wrap(err, "failed to get route URL for kibana")
Expand All @@ -96,6 +101,11 @@ func (clusterRequest *KibanaRequest) createOrUpdateKibanaConsoleLink() error {
func (clusterRequest *KibanaRequest) createOrUpdateKibanaConsoleExternalLogLink() (err error) {
cluster := clusterRequest.cluster

if !console.ConsoleExternalLogLinkEnabled(clusterRequest.client) {
clusterRequest.log.Info("ConsoleExternalLogLink kind is not found, skipping console external log link creation")
return nil
}

kibanaURL, err := clusterRequest.GetRouteURL("kibana")
if err != nil {
return kverrors.Wrap(err, "failed to get route URL", "cluster", clusterRequest.cluster.Name)
Expand Down
2 changes: 1 addition & 1 deletion internal/manifests/console/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewConsoleExternalLogLink(consoleText, hrefTemplate string, labels map[stri
APIVersion: consolev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: consoleExternalLogLinkName,
Name: ExternalLogLinkName,
Labels: labels,
},
Spec: consolev1.ConsoleExternalLogLinkSpec{
Expand Down
24 changes: 20 additions & 4 deletions internal/manifests/console/consoleexternalloglink.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import (
"context"

"github.com/ViaQ/logerr/v2/kverrors"
"github.com/go-logr/logr"
consolev1 "github.com/openshift/api/console/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metaerrors "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -19,7 +22,7 @@ type ConsoleExternalLogLinkEqualityFunc func(current, desired *consolev1.Console
// by applying the values from the desired consoleexternalloglink.
type MutateConsoleExternalLogLinkFunc func(current, desired *consolev1.ConsoleExternalLogLink)

const consoleExternalLogLinkName = "kibana"
const ExternalLogLinkName = "kibana"

// CreateOrUpdateConsoleExternalLogLink attempts first to get the given consoleexternalloglink. If the
// consoleexternalloglink does not exist, the consoleexternalloglink will be created. Otherwise,
Expand Down Expand Up @@ -93,20 +96,33 @@ func MutateConsoleExternalLogLink(current, desired *consolev1.ConsoleExternalLog
current.Spec.Text = desired.Spec.Text
}

func DeleteConsoleExternalLogLink(ctx context.Context, c client.Client) error {
func DeleteConsoleExternalLogLink(ctx context.Context, c client.Client, log logr.Logger) error {
if !ConsoleExternalLogLinkEnabled(c) {
log.Info("ConsoleExternalLogLink kind is not found, skipping consoleexternalloglink deletion")
return nil
}

current := &consolev1.ConsoleExternalLogLink{
ObjectMeta: metav1.ObjectMeta{
Name: consoleExternalLogLinkName,
Name: ExternalLogLinkName,
},
}

if err := c.Delete(ctx, current); err != nil {
if !apierrors.IsNotFound(err) {
return kverrors.Wrap(err, "failed to delete consoleexternalloglink",
"name", consoleExternalLogLinkName,
"name", ExternalLogLinkName,
)
}
}

return nil
}

func ConsoleExternalLogLinkEnabled(client client.Client) bool {
current := &consolev1.ConsoleExternalLogLink{}
key := types.NamespacedName{Name: ExternalLogLinkName}
err := client.Get(context.TODO(), key, current)

return err == nil || !metaerrors.IsNoMatchError(err)
}
18 changes: 17 additions & 1 deletion internal/manifests/console/consolelink.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import (
"context"

"github.com/ViaQ/logerr/v2/kverrors"
"github.com/go-logr/logr"
consolev1 "github.com/openshift/api/console/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metaerrors "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -72,7 +75,12 @@ func CreateOrUpdateConsoleLink(ctx context.Context, c client.Client, cl *console
return nil
}

func DeleteKibanaConsoleLink(ctx context.Context, c client.Client) error {
func DeleteKibanaConsoleLink(ctx context.Context, c client.Client, log logr.Logger) error {
if !ConsoleLinkEnabled(c) {
log.Info("ConsoleLink kind is not found, skipping console link deletion")
return nil
}

current := NewConsoleLink(KibanaConsoleLinkName, "", "", "", "")

if err := c.Delete(ctx, current); err != nil {
Expand Down Expand Up @@ -116,3 +124,11 @@ func ConsoleLinksEqual(current, desired *consolev1.ConsoleLink) bool {
func MutateConsoleLinkSpecOnly(current, desired *consolev1.ConsoleLink) {
current.Spec = desired.Spec
}

func ConsoleLinkEnabled(client client.Client) bool {
current := &consolev1.ConsoleLink{}
key := types.NamespacedName{Name: KibanaConsoleLinkName}
err := client.Get(context.TODO(), key, current)

return err == nil || !metaerrors.IsNoMatchError(err)
}

0 comments on commit b73db7b

Please sign in to comment.