Skip to content

Commit 5456f7c

Browse files
committed
Merge pull request redhat-developer#1088 from olivergondza/fix-intellij-idea-integration
chore(deps): Replace k8s deps that have version 0.0.0
2 parents bfb60dd + 9c5f041 commit 5456f7c

13 files changed

Lines changed: 1137 additions & 72 deletions

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ COPY controllers/ controllers/
1616
COPY common/ common/
1717
COPY version/ version/
1818

19-
# Build
20-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager ./cmd/main.go
19+
# Build - Use TARGETARCH to build for the correct architecture
20+
ARG TARGETARCH
21+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -a -o manager ./cmd/main.go
2122

2223
# Use distroless as minimal base image to package the manager binary
2324
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Makefile

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ IMG ?= $(IMAGE):$(VERSION)
6565
# Set the Operator SDK version to use.
6666
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
6767
OPERATOR_SDK_VERSION ?= v1.35.0
68-
68+
# Set the path to Operator SDK - OPERATOR_SDK_VERSION will be ignored.
69+
OPERATOR_SDK ?= bin/operator-sdk
6970

7071
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
7172
ifeq (,$(shell go env GOBIN))
@@ -131,19 +132,6 @@ test-e2e: manifests generate fmt vet ## Run e2e tests.
131132
test-metrics:
132133
go test -timeout 30m ./test/e2e -ginkgo.focus="Argo CD metrics controller" -coverprofile cover.out -ginkgo.v
133134

134-
.PHONY: operator-sdk
135-
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
136-
operator-sdk: ## Download operator-sdk locally if necessary.
137-
ifeq (,$(wildcard $(OPERATOR_SDK)))
138-
@{ \
139-
set -e ;\
140-
mkdir -p $(dir $(OPERATOR_SDK)) ;\
141-
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
142-
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
143-
chmod +x $(OPERATOR_SDK) ;\
144-
}
145-
endif
146-
147135
.PHONY: test-route
148136
test-route:
149137
go test -timeout 30m ./test/e2e -ginkgo.focus="Argo CD ConsoleLink controller" -coverprofile cover.out -ginkgo.v
@@ -211,7 +199,7 @@ build: generate fmt vet ## Build manager binary.
211199

212200
.PHONY: run
213201
run: manifests generate fmt vet ## Run a controller from your host.
214-
CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES=argo-rollouts,test-rom-ns-1,rom-ns-1,openshift-gitops ARGOCD_CLUSTER_CONFIG_NAMESPACES="openshift-gitops, argocd-e2e-cluster-config, argocd-test-impersonation-1-046, argocd-agent-principal-1-051, argocd-agent-agent-1-052, appset-argocd, appset-old-ns, appset-new-ns, ns-hosting-principal, ns-hosting-managed-agent, ns-hosting-autonomous-agent" REDIS_CONFIG_PATH="build/redis" go run ./cmd/main.go
202+
CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES=argo-rollouts,test-rom-ns-1,rom-ns-1,openshift-gitops ARGOCD_CLUSTER_CONFIG_NAMESPACES="openshift-gitops, argocd-e2e-cluster-config, argocd-test-impersonation-1-046, argocd-agent-principal-1-051, argocd-agent-agent-1-052, appset-argocd, appset-old-ns, appset-new-ns, ns-hosting-principal, ns-hosting-managed-agent, ns-hosting-autonomous-agent, appset-argocd-clusterrole" REDIS_CONFIG_PATH="build/redis" go run ./cmd/main.go
215203

216204
.PHONY: docker-build
217205
docker-build: test ## Build container image with the manager.
@@ -223,27 +211,17 @@ docker-push: ## Push container image with the manager.
223211

224212
##@ Build Dependencies
225213

226-
## Location to install dependencies to
227-
LOCALBIN ?= $(shell pwd)/bin
228-
$(LOCALBIN):
229-
mkdir -p $(LOCALBIN)
214+
# Do not use OPERATOR_SDK variable not to overwrite the user provided path
215+
bin/operator-sdk:
216+
mkdir -p bin
217+
curl -sSLo bin/operator-sdk \
218+
https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$(shell go env GOOS)_$(shell go env GOARCH)
219+
chmod +x bin/operator-sdk
230220

221+
# Install to bin/operator-sdk unless already there or explicit OPERATOR_SDK provided
231222
.PHONY: operator-sdk
232-
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
233-
operator-sdk: ## Download operator-sdk locally if necessary.
234-
ifeq (,$(wildcard $(OPERATOR_SDK)))
235-
ifeq (,$(shell which operator-sdk 2>/dev/null))
236-
@{ \
237-
set -e ;\
238-
mkdir -p $(dir $(OPERATOR_SDK)) ;\
239-
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
240-
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
241-
chmod +x $(OPERATOR_SDK) ;\
242-
}
243-
else
244-
OPERATOR_SDK = $(shell which operator-sdk)
245-
endif
246-
endif
223+
operator-sdk: $(OPERATOR_SDK)
224+
@$(OPERATOR_SDK) version
247225

248226
ifndef ignore-not-found
249227
ignore-not-found = false
@@ -368,7 +346,7 @@ gosec: go_sec
368346
.PHONY: lint
369347
lint: golangci_lint
370348
$(GOLANGCI_LINT) --version
371-
GOMAXPROCS=2 $(GOLANGCI_LINT) run --fix --verbose --timeout 300s
349+
$(GOLANGCI_LINT) run --fix --verbose --timeout 300s
372350

373351

374352
GO_SEC = $(shell pwd)/bin/gosec
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Enhancing OpenShift Lightspeed with Custom Knowledge
2+
3+
## Overview
4+
This guide explains how to extend the intelligence of OpenShift Lightspeed by integrating specialized knowledge for Argo CD, the Argo CD Operator, and the GitOps Operator. By configuring a custom Retrieval-Augmented Generation (RAG) database, you ensure the service provides precise, context-aware assistance for your GitOps queries.
5+
6+
The OpenShift Lightspeed service leverages Large Language Models (LLMs) to provide intelligent, context-aware responses. To ensure the model has deep expertise in your specific environment, you can use the Bring Your Own (BYO) Knowledge tool to integrate a Retrieval-Augmented Generation (RAG) database.
7+
8+
By connecting this database, you bridge the gap between general AI knowledge and specific technical documentation, ensuring more accurate troubleshooting and configuration advice.
9+
10+
11+
## Pre-packaged Knowledge for GitOps
12+
We have curated and optimized specialized knowledge sets for the following components:
13+
14+
* ArgoCD
15+
* ArgoCD Operator
16+
* Red Hat OpenShift GitOps Operator
17+
* ArgoCD Agent
18+
19+
This knowledge is packaged into a container [image](https://quay.io/devtools_gitops/argocd_lightspeed_byok:v0.0.4) and can be configured in Lightspeed using the instructions below.
20+
21+
## Prerequisites
22+
23+
* You are logged in to the OpenShift Container Platform web console as a user account that has permission to create a cluster-scoped custom resource (CR) file, such as a user with the cluster-admin role.
24+
* You have an LLM provider available for use with the OpenShift Lightspeed Service.
25+
* You have installed and configured the [OpenShift Lightspeed Operator](https://docs.redhat.com/en/documentation/red_hat_openshift_lightspeed/1.0/html/configure/ols-configuring-openshift-lightspeed).
26+
27+
Modify the OLSconfig CR to deploy the pre-packaged RAG database alongside the existing one:
28+
29+
* In the OpenShift Container Platform web console, click Operators >> Installed Operators.
30+
* Select All Projects in the Project dropdown at the top of the screen.
31+
* Click OpenShift Lightspeed Operator.
32+
* Click OLSConfig, then click the cluster configuration instance in the list.
33+
* Click the YAML tab.
34+
* Insert the spec.ols.rag yaml code:
35+
Example OLSconfig CR file
36+
37+
```bash
38+
apiVersion: ols.openshift.io/v1alpha1
39+
kind: OLSConfig
40+
metadata:
41+
name: cluster
42+
spec:
43+
ols:
44+
rag:
45+
- image: quay.io/devtools_gitops/argocd_lightspeed_byok:v0.0.4
46+
```
47+
48+
Note: Where image specifies the tag for the image that is present in the image registry so that the OpenShift Lightspeed Operator can access the custom content.
49+
* Click Save.

go.mod

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ require (
198198
)
199199

200200
replace (
201+
// This replace block is from Argo CD v3.3.0 go.mod
201202
github.com/golang/protobuf => github.com/golang/protobuf v1.5.4
202203
github.com/grpc-ecosystem/grpc-gateway => github.com/grpc-ecosystem/grpc-gateway v1.16.0
203204

@@ -206,4 +207,38 @@ replace (
206207

207208
// Avoid CVE-2022-28948
208209
gopkg.in/yaml.v3 => gopkg.in/yaml.v3 v3.0.1
210+
211+
// This replace block is from Argo CD v3.3.0 go.mod
212+
k8s.io/api => k8s.io/api v0.34.0
213+
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.34.0
214+
k8s.io/apimachinery => k8s.io/apimachinery v0.34.0
215+
k8s.io/apiserver => k8s.io/apiserver v0.34.0
216+
k8s.io/cli-runtime => k8s.io/cli-runtime v0.34.0
217+
k8s.io/client-go => k8s.io/client-go v0.34.0
218+
k8s.io/cloud-provider => k8s.io/cloud-provider v0.34.0
219+
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.34.0
220+
k8s.io/code-generator => k8s.io/code-generator v0.34.0
221+
k8s.io/component-base => k8s.io/component-base v0.34.0
222+
k8s.io/component-helpers => k8s.io/component-helpers v0.34.0
223+
k8s.io/controller-manager => k8s.io/controller-manager v0.34.0
224+
k8s.io/cri-api => k8s.io/cri-api v0.34.0
225+
k8s.io/cri-client => k8s.io/cri-client v0.34.0
226+
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.34.0
227+
k8s.io/dynamic-resource-allocation => k8s.io/dynamic-resource-allocation v0.34.0
228+
k8s.io/endpointslice => k8s.io/endpointslice v0.34.0
229+
k8s.io/externaljwt => k8s.io/externaljwt v0.34.0
230+
k8s.io/kms => k8s.io/kms v0.34.0
231+
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.34.0
232+
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.34.0
233+
k8s.io/kube-proxy => k8s.io/kube-proxy v0.34.0
234+
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.34.0
235+
k8s.io/kubectl => k8s.io/kubectl v0.34.0
236+
k8s.io/kubelet => k8s.io/kubelet v0.34.0
237+
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.34.0
238+
k8s.io/metrics => k8s.io/metrics v0.34.0
239+
k8s.io/mount-utils => k8s.io/mount-utils v0.34.0
240+
k8s.io/pod-security-admission => k8s.io/pod-security-admission v0.34.0
241+
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.34.0
242+
k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.34.0
243+
k8s.io/sample-controller => k8s.io/sample-controller v0.34.0
209244
)

go.sum

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -654,20 +654,20 @@ gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
654654
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
655655
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
656656
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
657-
k8s.io/api v0.34.1 h1:jC+153630BMdlFukegoEL8E/yT7aLyQkIVuwhmwDgJM=
658-
k8s.io/api v0.34.1/go.mod h1:SB80FxFtXn5/gwzCoN6QCtPD7Vbu5w2n1S0J5gFfTYk=
659-
k8s.io/apiextensions-apiserver v0.34.1 h1:NNPBva8FNAPt1iSVwIE0FsdrVriRXMsaWFMqJbII2CI=
660-
k8s.io/apiextensions-apiserver v0.34.1/go.mod h1:hP9Rld3zF5Ay2Of3BeEpLAToP+l4s5UlxiHfqRaRcMc=
661-
k8s.io/apimachinery v0.34.1 h1:dTlxFls/eikpJxmAC7MVE8oOeP1zryV7iRyIjB0gky4=
662-
k8s.io/apimachinery v0.34.1/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw=
663-
k8s.io/apiserver v0.34.1 h1:U3JBGdgANK3dfFcyknWde1G6X1F4bg7PXuvlqt8lITA=
664-
k8s.io/apiserver v0.34.1/go.mod h1:eOOc9nrVqlBI1AFCvVzsob0OxtPZUCPiUJL45JOTBG0=
657+
k8s.io/api v0.34.0 h1:L+JtP2wDbEYPUeNGbeSa/5GwFtIA662EmT2YSLOkAVE=
658+
k8s.io/api v0.34.0/go.mod h1:YzgkIzOOlhl9uwWCZNqpw6RJy9L2FK4dlJeayUoydug=
659+
k8s.io/apiextensions-apiserver v0.34.0 h1:B3hiB32jV7BcyKcMU5fDaDxk882YrJ1KU+ZSkA9Qxoc=
660+
k8s.io/apiextensions-apiserver v0.34.0/go.mod h1:hLI4GxE1BDBy9adJKxUxCEHBGZtGfIg98Q+JmTD7+g0=
661+
k8s.io/apimachinery v0.34.0 h1:eR1WO5fo0HyoQZt1wdISpFDffnWOvFLOOeJ7MgIv4z0=
662+
k8s.io/apimachinery v0.34.0/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw=
663+
k8s.io/apiserver v0.34.0 h1:Z51fw1iGMqN7uJ1kEaynf2Aec1Y774PqU+FVWCFV3Jg=
664+
k8s.io/apiserver v0.34.0/go.mod h1:52ti5YhxAvewmmpVRqlASvaqxt0gKJxvCeW7ZrwgazQ=
665665
k8s.io/cli-runtime v0.34.0 h1:N2/rUlJg6TMEBgtQ3SDRJwa8XyKUizwjlOknT1mB2Cw=
666666
k8s.io/cli-runtime v0.34.0/go.mod h1:t/skRecS73Piv+J+FmWIQA2N2/rDjdYSQzEE67LUUs8=
667-
k8s.io/client-go v0.34.1 h1:ZUPJKgXsnKwVwmKKdPfw4tB58+7/Ik3CrjOEhsiZ7mY=
668-
k8s.io/client-go v0.34.1/go.mod h1:kA8v0FP+tk6sZA0yKLRG67LWjqufAoSHA2xVGKw9Of8=
669-
k8s.io/component-base v0.34.1 h1:v7xFgG+ONhytZNFpIz5/kecwD+sUhVE6HU7qQUiRM4A=
670-
k8s.io/component-base v0.34.1/go.mod h1:mknCpLlTSKHzAQJJnnHVKqjxR7gBeHRv0rPXA7gdtQ0=
667+
k8s.io/client-go v0.34.0 h1:YoWv5r7bsBfb0Hs2jh8SOvFbKzzxyNo0nSb0zC19KZo=
668+
k8s.io/client-go v0.34.0/go.mod h1:ozgMnEKXkRjeMvBZdV1AijMHLTh3pbACPvK7zFR+QQY=
669+
k8s.io/component-base v0.34.0 h1:bS8Ua3zlJzapklsB1dZgjEJuJEeHjj8yTu1gxE2zQX8=
670+
k8s.io/component-base v0.34.0/go.mod h1:RSCqUdvIjjrEm81epPcjQ/DS+49fADvGSCkIP3IC6vg=
671671
k8s.io/component-helpers v0.34.0 h1:5T7P9XGMoUy1JDNKzHf0p/upYbeUf8ZaSf9jbx0QlIo=
672672
k8s.io/component-helpers v0.34.0/go.mod h1:kaOyl5tdtnymriYcVZg4uwDBe2d1wlIpXyDkt6sVnt4=
673673
k8s.io/controller-manager v0.34.0 h1:oCHoqS8dcFp7zDSu7HUvTpakq3isSxil3GprGGlJMsE=

test/openshift/e2e/ginkgo/fixture/application/fixture.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package application
22

33
import (
4+
"fmt"
5+
"regexp"
6+
47
. "github.com/onsi/gomega"
58
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils"
69
"k8s.io/client-go/util/retry"
@@ -83,6 +86,40 @@ func HaveSyncStatusCode(expected appv1alpha1.SyncStatusCode) matcher.GomegaMatch
8386

8487
}
8588

89+
func HaveNoConditions() matcher.GomegaMatcher {
90+
return expectedCondition(func(app *appv1alpha1.Application) bool {
91+
count := len(app.Status.Conditions)
92+
if count == 0 {
93+
return true
94+
}
95+
96+
GinkgoWriter.Printf("HaveNoConditions - have: %+v\n", app.Status.Conditions)
97+
return false
98+
})
99+
}
100+
101+
func HaveConditionMatching(conditionType appv1alpha1.ApplicationConditionType, messagePattern string) matcher.GomegaMatcher {
102+
pattern := regexp.MustCompile(messagePattern)
103+
104+
return expectedCondition(func(app *appv1alpha1.Application) bool {
105+
conditions := app.Status.Conditions
106+
var found []string
107+
for _, condition := range conditions {
108+
found = append(found, fmt.Sprintf(" - %s/%s", condition.Type, condition.Message))
109+
110+
if condition.Type == conditionType && pattern.MatchString(condition.Message) {
111+
return true
112+
}
113+
}
114+
115+
GinkgoWriter.Printf("HaveConditionMatching - expected: %s/%s; current(%d):\n", conditionType, messagePattern, len(conditions))
116+
for _, f := range found {
117+
GinkgoWriter.Println(f)
118+
}
119+
return false
120+
})
121+
}
122+
86123
// Update will keep trying to update object until it succeeds, or times out.
87124
func Update(obj *appv1alpha1.Application, modify func(*appv1alpha1.Application)) {
88125
k8sClient, _ := utils.GetE2ETestKubeClient()

test/openshift/e2e/ginkgo/fixture/argocd/fixture.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,32 +191,33 @@ func HaveExternalAuthenticationCondition(expected metav1.Condition) matcher.Gome
191191
func HaveCondition(condition metav1.Condition) matcher.GomegaMatcher {
192192
return fetchArgoCD(func(argocd *argov1beta1api.ArgoCD) bool {
193193

194-
if len(argocd.Status.Conditions) != 1 {
195-
GinkgoWriter.Println("HaveCondition: length is zero")
194+
length := len(argocd.Status.Conditions)
195+
if length != 1 {
196+
GinkgoWriter.Printf("HaveCondition: length is %d\n", length)
196197
return false
197198
}
198199

199200
instanceCondition := argocd.Status.Conditions[0]
200201

201-
GinkgoWriter.Println("HaveCondition - Message:", instanceCondition.Message, condition.Message)
202+
GinkgoWriter.Printf("HaveCondition - Message: '%s' / actual: '%s'\n", condition.Message, instanceCondition.Message)
202203
if instanceCondition.Message != condition.Message {
203204
GinkgoWriter.Println("HaveCondition: message does not match")
204205
return false
205206
}
206207

207-
GinkgoWriter.Println("HaveCondition - Reason:", instanceCondition.Reason, condition.Reason)
208+
GinkgoWriter.Printf("HaveCondition - Reason: '%s' / actual: '%s'\n", condition.Reason, instanceCondition.Reason)
208209
if instanceCondition.Reason != condition.Reason {
209210
GinkgoWriter.Println("HaveCondition: reason does not match")
210211
return false
211212
}
212213

213-
GinkgoWriter.Println("HaveCondition - Status:", instanceCondition.Status, condition.Status)
214+
GinkgoWriter.Printf("HaveCondition - Status: '%s' / actual: '%s'\n", condition.Status, instanceCondition.Status)
214215
if instanceCondition.Status != condition.Status {
215216
GinkgoWriter.Println("HaveCondition: status does not match")
216217
return false
217218
}
218219

219-
GinkgoWriter.Println("HaveCondition - Type:", instanceCondition.Type, condition.Type)
220+
GinkgoWriter.Printf("HaveCondition - Type: '%s' / actual: '%s'\n", condition.Type, instanceCondition.Type)
220221
if instanceCondition.Type != condition.Type {
221222
GinkgoWriter.Println("HaveCondition: type does not match")
222223
return false

test/openshift/e2e/ginkgo/fixture/clusterrole/fixture.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package clusterrole
22

33
import (
44
"context"
5+
"reflect"
56

67
. "github.com/onsi/ginkgo/v2"
78
. "github.com/onsi/gomega"
@@ -32,6 +33,13 @@ func Update(obj *rbacv1.ClusterRole, modify func(*rbacv1.ClusterRole)) {
3233

3334
}
3435

36+
func HaveRules(expectedRules []rbacv1.PolicyRule) matcher.GomegaMatcher {
37+
return fetchRole(func(cr *rbacv1.ClusterRole) bool {
38+
GinkgoWriter.Println("HaveRules - Expected:", expectedRules, "/ Actual:", cr.Rules)
39+
return reflect.DeepEqual(expectedRules, cr.Rules)
40+
})
41+
}
42+
3543
// This is intentionally NOT exported, for now. Create another function in this file/package that calls this function, and export that.
3644
//
3745
//nolint:unused

test/openshift/e2e/ginkgo/fixture/k8s/fixture.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,23 @@ func NotHaveLabelWithValue(key string, value string) matcher.GomegaMatcher {
9898
// ExistByName checks if the given k8s resource exists, when retrieving it by name/namespace.
9999
// - It does NOT check if the resource content matches. It only checks that a resource of that type and name exists.
100100
func ExistByName() matcher.GomegaMatcher {
101+
return ExistByNameWithClient(nil)
102+
}
101103

102-
return WithTransform(func(k8sObject client.Object) bool {
103-
k8sClient, _, err := utils.GetE2ETestKubeClientWithError()
104-
if err != nil {
105-
GinkgoWriter.Println(err)
106-
return false
107-
}
104+
// ExistByNameWithClient checks if the given k8s resource exists, when retrieving it by name/namespace.
105+
// - It does NOT check if the resource content matches. It only checks that a resource of that type and name exists.
106+
//
107+
// NOTE: you probably want to instead use ExistByName()
108+
func ExistByNameWithClient(k8sClient client.Client) matcher.GomegaMatcher {
109+
if k8sClient == nil {
110+
var err error
111+
k8sClient, _, err = utils.GetE2ETestKubeClientWithError()
112+
Expect(err).ToNot(HaveOccurred())
113+
Expect(k8sClient).ShouldNot(BeNil())
114+
}
108115

109-
err = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(k8sObject), k8sObject)
116+
return WithTransform(func(k8sObject client.Object) bool {
117+
err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(k8sObject), k8sObject)
110118
if err != nil {
111119
GinkgoWriter.Println("Object does not exists in ExistByName:", k8sObject.GetName(), err)
112120
} else {

0 commit comments

Comments
 (0)