Skip to content

🌱 In-tree test operator #2070

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,18 @@ test-unit: $(SETUP_ENVTEST) envtest-k8s-bins #HELP Run the unit tests
$(UNIT_TEST_DIRS) \
-test.gocoverdir=$(COVERAGE_UNIT_DIR)

TEST_OPERATOR_CONTROLLERS_HOME=./testdata/images/controllers
TEST_OPERATOR_CONTROLLERS=v1.0.0 v2.0.0

.PHONY: $(TEST_OPERATOR_CONTROLLERS)
$(TEST_OPERATOR_CONTROLLERS):
go build $(GO_BUILD_FLAGS) $(GO_BUILD_EXTRA_FLAGS) -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o $(TEST_OPERATOR_CONTROLLERS_HOME)/test-operator/$@/manager ./testdata/images/bundles/test-operator/$@/cmd/main.go

.PHONY: image-registry
E2E_REGISTRY_IMAGE=localhost/e2e-test-registry:devel
image-registry: export GOOS=linux
image-registry: export GOARCH=amd64
image-registry: ## Build the testdata catalog used for e2e tests and push it to the image registry
go build $(GO_BUILD_FLAGS) $(GO_BUILD_EXTRA_FLAGS) -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o ./testdata/registry/bin/registry ./testdata/registry/registry.go
image-registry: $(TEST_OPERATOR_CONTROLLERS) ## Build the testdata catalog used for e2e tests and push it to the image registry
go build $(GO_BUILD_FLAGS) $(GO_BUILD_EXTRA_FLAGS) -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o ./testdata/push/bin/push ./testdata/push/push.go
$(CONTAINER_RUNTIME) build -f ./testdata/Dockerfile -t $(E2E_REGISTRY_IMAGE) ./testdata
$(CONTAINER_RUNTIME) save $(E2E_REGISTRY_IMAGE) | $(KIND) load image-archive /dev/stdin --name $(KIND_CLUSTER_NAME)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[host."https://localhost:30000"]
capabilities = ["pull", "resolve"]
skip_verify = true
7 changes: 7 additions & 0 deletions kind-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ nodes:
apiServer:
extraArgs:
enable-admission-plugins: OwnerReferencesPermissionEnforcement
extraMounts:
- hostPath: ./hack/kind-config/containerd/certs.d
containerPath: /etc/containerd/certs.d
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/containerd/certs.d"
2 changes: 1 addition & 1 deletion test/e2e/cluster_extension_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ func TestClusterExtensionInstallReResolvesWhenCatalogIsPatched(t *testing.T) {
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
assert.Equal(ct, ocv1.ReasonSucceeded, cond.Reason)
assert.Contains(ct, cond.Message, "Installed bundle")
assert.Contains(ct, clusterExtension.Status.Install.Bundle.Version, "2.0.0")
assert.Contains(ct, clusterExtension.Status.Install.Bundle.Version, "1.3.0")
}
}, pollDuration, pollInterval)

Expand Down
2 changes: 1 addition & 1 deletion testdata/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
push/bin
registry/bin
images/controllers
3 changes: 0 additions & 3 deletions testdata/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ FROM gcr.io/distroless/static:nonroot

WORKDIR /

COPY registry/bin/registry registry
COPY push/bin/push push

COPY images images

EXPOSE 5000

USER 65532:65532
6 changes: 1 addition & 5 deletions testdata/build-test-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,8 @@ spec:
spec:
containers:
- name: registry
image: ${image}
image: registry:3
imagePullPolicy: IfNotPresent
command:
- /registry
args:
- "--registry-address=:5000"
volumeMounts:
- name: certs-vol
mountPath: "/certs"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1 contains API Schema definitions for the testolm v1 API group.
// +kubebuilder:object:generate=false
// +groupName=testolm.operatorframework.io
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "testolm.operatorframework.io", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// TestOperatorSpec defines the desired state of TestOperator.
type TestOperatorSpec struct {
// +optional
Message string `json:"message,omitempty"`
}

// TestOperatorStatus defines the observed state of TestOperator.
type TestOperatorStatus struct {
Echo string `json:"echo,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// TestOperator is the Schema for the testoperators API.
type TestOperator struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec TestOperatorSpec `json:"spec,omitempty"`
Status TestOperatorStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// TestOperatorList contains a list of TestOperator.
type TestOperatorList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []TestOperator `json:"items"`
}

func init() {
SchemeBuilder.Register(&TestOperator{}, &TestOperatorList{})
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading