Skip to content

Commit 6a0d442

Browse files
✨ Add oci as assets client
Implemented the oci client to download artifacts from an oci registry. Signed-off-by: Janis Kemper <[email protected]> Co-authored-by: Roman Hros <[email protected]>
1 parent 44b4f81 commit 6a0d442

File tree

115 files changed

+13070
-61
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+13070
-61
lines changed

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,19 @@ jobs:
6969
GO111MODULE: "on"
7070
GIT_ACCESS_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
7171
run: make test-integration-workloadcluster
72+
73+
- name: Running integration tests github
74+
env:
75+
GIT_PROVIDER: github
76+
GIT_ORG_NAME: SovereignCloudStack
77+
GIT_REPOSITORY_NAME: cluster-stacks
78+
GO111MODULE: "on"
79+
GIT_ACCESS_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
80+
run: make test-integration-github
81+
82+
# - name: Running integration tests oci
83+
# env:
84+
# OCI_REGISTRY: registry.scs.community
85+
# OCI_REPOSITORY: registry.scs.community/csctl-oci/docker
86+
# GO111MODULE: "on"
87+
# run: make test-integration-oci

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ $(WORKER_CLUSTER_KUBECONFIG):
304304
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env --bin-dir $(abspath $(TOOLS_BIN_DIR)) -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))
305305

306306
.PHONY: test-integration
307-
test-integration: test-integration-workloadcluster test-integration-github
307+
test-integration: test-integration-workloadcluster test-integration-github test-integration-oci
308308
echo done
309309

310310
.PHONY: test-unit
@@ -325,6 +325,12 @@ test-integration-github: $(SETUP_ENVTEST) $(GOTESTSUM)
325325
CREATE_KIND_CLUSTER=false KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GOTESTSUM) --junitfile=.coverage/junit.xml --format testname -- -mod=vendor \
326326
-covermode=atomic -coverprofile=.coverage/cover.out -p=1 ./internal/test/integration/github/...
327327

328+
.PHONY: test-integration-oci
329+
test-integration-oci: $(SETUP_ENVTEST) $(GOTESTSUM)
330+
@mkdir -p $(shell pwd)/.coverage
331+
CREATE_KIND_CLUSTER=false KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GOTESTSUM) --junitfile=.coverage/junit.xml --format testname -- -mod=vendor \
332+
-covermode=atomic -coverprofile=.coverage/cover.out -p=1 ./internal/test/integration/oci/...
333+
328334
##@ Verify
329335
##########
330336
# Verify #

cmd/main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
package main
1919

2020
import (
21+
"errors"
2122
"flag"
2223
"fmt"
2324
"os"
@@ -31,6 +32,7 @@ import (
3132
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient"
3233
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient/fake"
3334
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient/github"
35+
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient/oci"
3436
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/csoversion"
3537
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/kube"
3638
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/utillog"
@@ -83,6 +85,7 @@ var (
8385
logLevel string
8486
releaseDir string
8587
localMode bool
88+
source string
8689
qps float64
8790
burst int
8891
hookPort int
@@ -101,7 +104,8 @@ func main() {
101104
flag.IntVar(&clusterAddonConcurrency, "clusteraddon-concurrency", 1, "Number of ClusterAddons to process simultaneously")
102105
flag.StringVar(&logLevel, "log-level", "info", "Specifies log level. Options are 'debug', 'info' and 'error'")
103106
flag.StringVar(&releaseDir, "release-dir", "/tmp/downloads/", "Specify release directory for cluster-stack releases")
104-
flag.BoolVar(&localMode, "local", false, "Enable local mode where no release assets will be downloaded from a remote Git repository. Useful for implementing cluster stacks.")
107+
flag.BoolVar(&localMode, "local", false, "Enable local mode where no release assets will be downloaded from a remote repository. Useful for implementing cluster stacks.")
108+
flag.StringVar(&source, "source", "github", "Specifies the source from which release assets would be downloaded. Allowed sources are 'github' and 'oci'")
105109
flag.Float64Var(&qps, "qps", 50, "Enable custom query per second for kubernetes API server")
106110
flag.IntVar(&burst, "burst", 100, "Enable custom burst defines how many queries the API server will accept before enforcing the limit established by qps")
107111
flag.IntVar(&hookPort, "hook-port", 9442, "hook server port")
@@ -150,7 +154,15 @@ func main() {
150154
if localMode {
151155
assetsClientFactory = fake.NewFactory()
152156
} else {
153-
assetsClientFactory = github.NewFactory()
157+
switch source {
158+
case "oci":
159+
assetsClientFactory = oci.NewFactory()
160+
case "github":
161+
assetsClientFactory = github.NewFactory()
162+
default:
163+
setupLog.Error(errors.New("invalid asset source"), "no valid source specified, allowed sources are 'github' and 'oci'")
164+
os.Exit(1)
165+
}
154166
}
155167

156168
restConfig := mgr.GetConfig()

config/manager/credentials.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ data:
99
git-org-name: ${GIT_ORG_NAME_B64:=""}
1010
git-repo-name: ${GIT_REPOSITORY_NAME_B64:=""}
1111
git-access-token: ${GIT_ACCESS_TOKEN_B64:=""}
12+
oci-registry: ${OCI_REGISTRY_B64:=""}
13+
oci-repository: ${OCI_REPOSITORY_B64:=""}
14+
oci-access-token: ${OCI_ACCESS_TOKEN_B64:=""}
15+
oci-username: ${OCI_USERNAME_B64:=""}
16+
oci-password: ${OCI_PASSWORD_B64:=""}

config/manager/manager.yaml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ spec:
2727
containers:
2828
- command:
2929
- /manager
30-
args:
31-
- --leader-elect=true
3230
env:
3331
- name: GIT_PROVIDER
3432
valueFrom:
@@ -50,6 +48,34 @@ spec:
5048
secretKeyRef:
5149
name: cso-cluster-stack-variables
5250
key: git-access-token
51+
- name: OCI_REGISTRY
52+
valueFrom:
53+
secretKeyRef:
54+
name: cso-cluster-stack-variables
55+
key: oci-registry
56+
- name: OCI_REPOSITORY
57+
valueFrom:
58+
secretKeyRef:
59+
name: cso-cluster-stack-variables
60+
key: oci-repository
61+
- name: OCI_ACCESS_TOKEN
62+
valueFrom:
63+
secretKeyRef:
64+
name: cso-cluster-stack-variables
65+
key: oci-access-token
66+
- name: OCI_USERNAME
67+
valueFrom:
68+
secretKeyRef:
69+
name: cso-cluster-stack-variables
70+
key: oci-username
71+
- name: OCI_PASSWORD
72+
valueFrom:
73+
secretKeyRef:
74+
name: cso-cluster-stack-variables
75+
key: oci-password
76+
args:
77+
- --leader-elect=true
78+
- --log-level=info
5379
image: controller:latest
5480
name: manager
5581
ports:

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22
55
require (
66
github.com/go-logr/logr v1.4.2
77
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572
8-
github.com/google/cel-go v0.19.0
8+
github.com/google/cel-go v0.20.1
99
github.com/google/go-github/v52 v52.0.0
1010
github.com/onsi/ginkgo/v2 v2.19.0
1111
github.com/onsi/gomega v1.33.1
@@ -17,6 +17,7 @@ require (
1717
k8s.io/cli-runtime v0.29.3
1818
k8s.io/client-go v0.29.3
1919
k8s.io/klog/v2 v2.110.1
20+
oras.land/oras-go/v2 v2.5.0
2021
sigs.k8s.io/cluster-api v1.7.2
2122
sigs.k8s.io/cluster-api/test v1.7.2
2223
sigs.k8s.io/controller-runtime v0.17.5
@@ -35,6 +36,8 @@ require (
3536
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3637
github.com/mattn/go-isatty v0.0.20 // indirect
3738
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
39+
github.com/opencontainers/go-digest v1.0.0 // indirect
40+
github.com/opencontainers/image-spec v1.1.0 // indirect
3841
github.com/pelletier/go-toml v1.9.5 // indirect
3942
github.com/pkg/errors v0.9.1 // indirect
4043
github.com/pmezard/go-difflib v1.0.0 // indirect

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
9090
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
9191
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
9292
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
93-
github.com/google/cel-go v0.19.0 h1:vVgaZoHPBDd1lXCYGQOh5A06L4EtuIfmqQ/qnSXSKiU=
94-
github.com/google/cel-go v0.19.0/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg=
93+
github.com/google/cel-go v0.20.1 h1:nDx9r8S3L4pE61eDdt8igGj8rf5kjYR3ILxWIpWNi84=
94+
github.com/google/cel-go v0.20.1/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg=
9595
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
9696
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
9797
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -163,6 +163,8 @@ github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
163163
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
164164
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
165165
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
166+
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
167+
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
166168
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
167169
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
168170
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -352,6 +354,8 @@ k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/A
352354
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
353355
k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6RxQGZDnzuLcrUTI=
354356
k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
357+
oras.land/oras-go/v2 v2.5.0 h1:o8Me9kLY74Vp5uw07QXPiitjsw7qNXi8Twd+19Zf02c=
358+
oras.land/oras-go/v2 v2.5.0/go.mod h1:z4eisnLP530vwIOUOJeBIj0aGI0L1C3d53atvCBqZHg=
355359
sigs.k8s.io/cluster-api v1.7.2 h1:bRE8zoao7ajuLC0HijqfZVcubKQCPlZ04HMgcA53FGE=
356360
sigs.k8s.io/cluster-api v1.7.2/go.mod h1:V9ZhKLvQtsDODwjXOKgbitjyCmC71yMBwDcMyNNIov0=
357361
sigs.k8s.io/cluster-api/test v1.7.2 h1:muacGu5G/DGz2uTv3CUxml2QLi8fxbIra4CxA2S31KE=

internal/controller/clusterstack_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (r *ClusterStackReconciler) Reconcile(ctx context.Context, req reconcile.Re
113113
var latest *string
114114

115115
if clusterStack.Spec.AutoSubscribe {
116-
gc, err := r.AssetsClientFactory.NewClient(ctx)
116+
ac, err := r.AssetsClientFactory.NewClient(ctx)
117117
if err != nil {
118118
isSet := conditions.IsFalse(clusterStack, csov1alpha1.AssetsClientAPIAvailableCondition)
119119
conditions.MarkFalse(clusterStack,
@@ -133,7 +133,7 @@ func (r *ClusterStackReconciler) Reconcile(ctx context.Context, req reconcile.Re
133133

134134
conditions.MarkTrue(clusterStack, csov1alpha1.AssetsClientAPIAvailableCondition)
135135

136-
latest, err = getLatestReleaseFromRemoteRepository(ctx, clusterStack, gc)
136+
latest, err = getLatestReleaseFromRemoteRepository(ctx, clusterStack, ac)
137137
if err != nil {
138138
// only log error and mark condition as false, but continue
139139
conditions.MarkFalse(clusterStack,

internal/test/integration/github/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ var _ = Describe("ClusterStackReconciler", func() {
144144

145145
clusterStackKey = types.NamespacedName{Name: clusterStack.Name, Namespace: testNs.Name}
146146

147-
cs, err := clusterstack.New(clusterStack.Spec.Provider, clusterStack.Spec.Name, clusterStack.Spec.KubernetesVersion, version)
147+
cs, err := clusterstack.New(clusterStack.Spec.Provider, clusterStack.Spec.Name, clusterStack.Spec.KubernetesVersion, "v2")
148148
Expect(err).To(BeNil())
149149

150150
clusterStackReleaseKey = types.NamespacedName{Name: cs.String(), Namespace: testNs.Name}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package oci
18+
19+
import (
20+
"path/filepath"
21+
"testing"
22+
"time"
23+
24+
"github.com/SovereignCloudStack/cluster-stack-operator/internal/controller"
25+
"github.com/SovereignCloudStack/cluster-stack-operator/internal/test/helpers"
26+
ociclient "github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient/oci"
27+
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/kube"
28+
fakekube "github.com/SovereignCloudStack/cluster-stack-operator/pkg/kube/fake"
29+
fakeworkloadcluster "github.com/SovereignCloudStack/cluster-stack-operator/pkg/workloadcluster/fake"
30+
. "github.com/onsi/ginkgo/v2"
31+
. "github.com/onsi/gomega"
32+
ctrl "sigs.k8s.io/controller-runtime"
33+
controllerruntimecontroller "sigs.k8s.io/controller-runtime/pkg/controller"
34+
)
35+
36+
const (
37+
timeout = time.Second * 10
38+
interval = 1000 * time.Millisecond
39+
releaseDir = "/tmp/downloads"
40+
)
41+
42+
func TestControllers(t *testing.T) {
43+
RegisterFailHandler(Fail)
44+
RunSpecs(t, "Controller Suite")
45+
}
46+
47+
var (
48+
ctx = ctrl.SetupSignalHandler()
49+
testEnv *helpers.TestEnvironment
50+
)
51+
52+
var _ = BeforeSuite(func() {
53+
testEnv = helpers.NewTestEnvironment()
54+
55+
Expect((&controller.ClusterStackReconciler{
56+
Client: testEnv.Manager.GetClient(),
57+
AssetsClientFactory: ociclient.NewFactory(),
58+
ReleaseDirectory: releaseDir,
59+
}).SetupWithManager(ctx, testEnv.Manager, controllerruntimecontroller.Options{})).To(Succeed())
60+
61+
Expect((&controller.ClusterStackReleaseReconciler{
62+
Client: testEnv.Manager.GetClient(),
63+
RESTConfig: testEnv.Manager.GetConfig(),
64+
KubeClientFactory: kube.NewFactory(),
65+
AssetsClientFactory: ociclient.NewFactory(),
66+
ReleaseDirectory: releaseDir,
67+
}).SetupWithManager(ctx, testEnv.Manager, controllerruntimecontroller.Options{})).To(Succeed())
68+
69+
Expect((&controller.ClusterAddonCreateReconciler{
70+
Client: testEnv.Manager.GetClient(),
71+
}).SetupWithManager(ctx, testEnv.Manager, controllerruntimecontroller.Options{})).To(Succeed())
72+
73+
Expect((&controller.ClusterAddonReconciler{
74+
Client: testEnv.Manager.GetClient(),
75+
KubeClientFactory: fakekube.NewFactory(),
76+
ReleaseDirectory: filepath.Join(releaseDir, "cluster-stacks"),
77+
WorkloadClusterFactory: fakeworkloadcluster.NewFactory(),
78+
}).SetupWithManager(ctx, testEnv.Manager, controllerruntimecontroller.Options{})).To(Succeed())
79+
80+
go func() {
81+
defer GinkgoRecover()
82+
Expect(testEnv.StartManager(ctx)).To(Succeed())
83+
}()
84+
85+
<-testEnv.Manager.Elected()
86+
87+
// wait for webhook port to be open prior to running tests
88+
testEnv.WaitForWebhooks()
89+
})
90+
91+
var _ = AfterSuite(func() {
92+
Expect(testEnv.Stop()).To(Succeed())
93+
})

0 commit comments

Comments
 (0)