Skip to content

Commit

Permalink
Add oci as assets client
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Hros <[email protected]>
  • Loading branch information
chess-knight committed Aug 27, 2024
1 parent 4349994 commit 60a59c8
Show file tree
Hide file tree
Showing 105 changed files with 12,971 additions and 10 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ generate-modules-ci: generate-modules
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env --bin-dir $(abspath $(TOOLS_BIN_DIR)) -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))

.PHONY: test-integration ## Run integration tests
test-integration: test-integration-github test-integration-openstack
test-integration: test-integration-openstack test-integration-github test-integration-oci
echo done

.PHONY: test-unit
Expand All @@ -513,6 +513,12 @@ test-integration-github: $(SETUP_ENVTEST) $(GOTESTSUM)
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GOTESTSUM) --junitfile=.coverage/junit.xml --format testname -- -mod=vendor \
-covermode=atomic -coverprofile=.coverage/cover.out -p=1 ./internal/test/integration/github/...

.PHONY: test-integration-oci
test-integration-oci: $(SETUP_ENVTEST) $(GOTESTSUM)
@mkdir -p $(shell pwd)/.coverage
OCI_REGISTRY=ghcr.io OCI_REPOSITORY="" KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GOTESTSUM) --junitfile=.coverage/junit.xml --format testname -- -mod=vendor \
-covermode=atomic -coverprofile=.coverage/cover.out -p=1 ./internal/test/integration/oci/...

.PHONY: test-integration-openstack
test-integration-openstack: $(SETUP_ENVTEST) $(GOTESTSUM)
@mkdir -p $(shell pwd)/.coverage
Expand Down
14 changes: 13 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ package main

// Import packages including all Kubernetes client auth plugins: k8s.io/client-go/plugin/pkg/client/auth.
import (
"errors"
"flag"
"os"
"time"

"github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient/fake"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient/github"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient/oci"
apiv1alpha1 "github.com/SovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
"github.com/SovereignCloudStack/cluster-stack-provider-openstack/internal/controller"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -54,6 +56,7 @@ var (
releaseDir string
imageImportTimeout int
localMode bool
source string
metricsAddr string
enableLeaderElection bool
probeAddr string
Expand All @@ -71,6 +74,7 @@ func main() {
flag.StringVar(&releaseDir, "release-dir", "/tmp/downloads/", "Specify release directory for cluster-stack releases")
flag.IntVar(&imageImportTimeout, "image-import-timeout", 0, "Maximum time in minutes that you allow cspo to import image. If image-import-timeout <= 0, cspo waits forever.")
flag.BoolVar(&localMode, "local", false, "Enable local mode where no release assets will be downloaded from a remote repository. Useful for implementing cluster stacks.")
flag.StringVar(&source, "source", "github", "Specifies the source from which release assets would be downloaded. Allowed sources are 'github' and 'oci'")

opts := zap.Options{
Development: true,
Expand Down Expand Up @@ -105,7 +109,15 @@ func main() {
if localMode {
assetsClientFactory = fake.NewFactory()
} else {
assetsClientFactory = github.NewFactory()
switch source {
case "oci":
assetsClientFactory = oci.NewFactory()
case "github":
assetsClientFactory = github.NewFactory()
default:
setupLog.Error(errors.New("invalid asset source"), "no valid source specified, allowed sources are 'github' and 'oci'")
os.Exit(1)
}
}

if err = (&controller.OpenStackClusterStackReleaseReconciler{
Expand Down
3 changes: 3 additions & 0 deletions config/manager/credentials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ data:
git-org-name: ${GIT_ORG_NAME_B64:=""}
git-repo-name: ${GIT_REPOSITORY_NAME_B64:=""}
git-access-token: ${GIT_ACCESS_TOKEN_B64:=""}
oci-registry: ${OCI_REGISTRY_B64:=""}
oci-repository: ${OCI_REPOSITORY_B64:=""}
oci-access-token: ${OCI_ACCESS_TOKEN_B64:=""}
15 changes: 15 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ spec:
secretKeyRef:
name: cspo-cluster-stack-variables
key: git-access-token
- name: OCI_REGISTRY
valueFrom:
secretKeyRef:
name: cso-cluster-stack-variables
key: oci-registry
- name: OCI_REPOSITORY
valueFrom:
secretKeyRef:
name: cso-cluster-stack-variables
key: oci-repository
- name: OCI_ACCESS_TOKEN
valueFrom:
secretKeyRef:
name: cso-cluster-stack-variables
key: oci-access-token
image: controller:latest
name: manager
securityContext:
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21.6
toolchain go1.22.1

require (
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.6
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.6.0.20240710163640-4ea42b753f21
github.com/gophercloud/gophercloud/v2 v2.0.0-beta.2
github.com/gophercloud/utils/v2 v2.0.0-20240305212012-b57aefba4cdb
github.com/onsi/ginkgo/v2 v2.19.0
Expand Down Expand Up @@ -60,6 +60,8 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
Expand All @@ -75,6 +77,7 @@ require (
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
Expand All @@ -89,6 +92,7 @@ require (
k8s.io/component-base v0.29.3 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20231127182322-b307cd553661 // indirect
oras.land/oras-go/v2 v2.5.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
12 changes: 8 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.6 h1:n+QpmV8C+rZZ5+nvA5PytpWWnD5Di/Xcyzdqih5jnzw=
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.6/go.mod h1:9tPLUQFLeoDb+LWErQYqfbIj+9TIOy9E4qyQOxmTHik=
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.6.0.20240710163640-4ea42b753f21 h1:aEwvjpTTJ1CPYuVbXXbsxfEX2+YcztxlwK3e2bw0nkQ=
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.6.0.20240710163640-4ea42b753f21/go.mod h1:eERjYBSOckgJ6Z2bUW1RxR3dh6bRVxUq6LWIHkIKu/k=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
Expand Down Expand Up @@ -63,8 +63,8 @@ github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/cel-go v0.19.0 h1:vVgaZoHPBDd1lXCYGQOh5A06L4EtuIfmqQ/qnSXSKiU=
github.com/google/cel-go v0.19.0/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg=
github.com/google/cel-go v0.20.1 h1:nDx9r8S3L4pE61eDdt8igGj8rf5kjYR3ILxWIpWNi84=
github.com/google/cel-go v0.20.1/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg=
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down Expand Up @@ -130,6 +130,8 @@ github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -268,6 +270,8 @@ k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/A
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6RxQGZDnzuLcrUTI=
k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
oras.land/oras-go/v2 v2.5.0 h1:o8Me9kLY74Vp5uw07QXPiitjsw7qNXi8Twd+19Zf02c=
oras.land/oras-go/v2 v2.5.0/go.mod h1:z4eisnLP530vwIOUOJeBIj0aGI0L1C3d53atvCBqZHg=
sigs.k8s.io/cluster-api v1.7.2 h1:bRE8zoao7ajuLC0HijqfZVcubKQCPlZ04HMgcA53FGE=
sigs.k8s.io/cluster-api v1.7.2/go.mod h1:V9ZhKLvQtsDODwjXOKgbitjyCmC71yMBwDcMyNNIov0=
sigs.k8s.io/cluster-api-provider-openstack v0.9.0 h1:ScwZIfT1kI88+qMzeO7ppMP9DvEzrfLHuYPg2p1mcho=
Expand Down
64 changes: 64 additions & 0 deletions internal/test/integration/oci/integration_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2023 The Kubernetes Authors.
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 oci

import (
"testing"
"time"

ociclient "github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient/oci"
"github.com/SovereignCloudStack/cluster-stack-provider-openstack/internal/controller"
"github.com/SovereignCloudStack/cluster-stack-provider-openstack/internal/test/helpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
ctrl "sigs.k8s.io/controller-runtime"
)

const (
timeout = time.Second * 10
interval = 1000 * time.Millisecond
releaseDir = "/tmp/downloads"
)

func TestControllers(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Controller Suite")
}

var (
ctx = ctrl.SetupSignalHandler()
testEnv *helpers.TestEnvironment
)

var _ = BeforeSuite(func() {
testEnv = helpers.NewTestEnvironment()
Expect((&controller.OpenStackClusterStackReleaseReconciler{
Client: testEnv.Manager.GetClient(),
AssetsClientFactory: ociclient.NewFactory(),
ReleaseDirectory: releaseDir,
}).SetupWithManager(testEnv.Manager)).To(Succeed())

go func() {
defer GinkgoRecover()
Expect(testEnv.StartManager(ctx)).To(Succeed())
}()
<-testEnv.Manager.Elected()
})

var _ = AfterSuite(func() {
Expect(testEnv.Stop()).To(Succeed())
})
109 changes: 109 additions & 0 deletions internal/test/integration/oci/integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
Copyright 2023 The Kubernetes Authors.
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 oci

import (
"encoding/base64"
"os"

"github.com/SovereignCloudStack/cluster-stack-operator/pkg/test/utils"
cspov1alpha1 "github.com/SovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
apiv1alpha7 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7"
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

var _ = Describe("OpenStackClusterStackReleaseReconciler", func() {
Context("test", func() {
var (
openStackClusterStackRelease *cspov1alpha1.OpenStackClusterStackRelease
testNs *corev1.Namespace
openstackClusterStackReleaseKey types.NamespacedName
)

BeforeEach(func() {
var err error
testNs, err = testEnv.CreateNamespace(ctx, "oscsr-integration")
Expect(err).NotTo(HaveOccurred())

openstackClusterStackReleaseKey = types.NamespacedName{Name: "openstack-scs-1-27-v2", Namespace: testNs.Name}

cloudsYAMLBase64 := os.Getenv("ENCODED_CLOUDS_YAML")
cloudsYAMLData, err := base64.StdEncoding.DecodeString(cloudsYAMLBase64)
Expect(err).NotTo(HaveOccurred())

secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "supersecret",
Namespace: testNs.Name,
},
Data: map[string][]byte{
"clouds.yaml": cloudsYAMLData,
},
}
Expect(testEnv.Create(ctx, secret)).To(Succeed())

openStackClusterStackRelease = &cspov1alpha1.OpenStackClusterStackRelease{
TypeMeta: metav1.TypeMeta{
Kind: "OpenStackClusterStackRelease",
APIVersion: "infrastructure.clusterstack.x-k8s.io",
},
ObjectMeta: metav1.ObjectMeta{
Name: "openstack-scs-1-27-v2",
Namespace: testNs.Name,
},
Spec: cspov1alpha1.OpenStackClusterStackReleaseSpec{
IdentityRef: &apiv1alpha7.OpenStackIdentityReference{
Kind: "Secret",
Name: "supersecret",
},
},
Status: cspov1alpha1.OpenStackClusterStackReleaseStatus{
Ready: false,
Conditions: clusterv1beta1.Conditions{},
},
}
Expect(testEnv.Create(ctx, openStackClusterStackRelease)).To(Succeed())
})

AfterEach(func() {
Expect(os.RemoveAll(releaseDir)).To(Succeed())
Eventually(func() error {
return testEnv.Cleanup(ctx, testNs, openStackClusterStackRelease)
}, timeout, interval).Should(BeNil())
})

It("creates the OpenStackNodeImageRelease object", func() {
openstackNodeImageReleaseName := types.NamespacedName{Name: "openstack-scs-1-27-ubuntu-capi-image-v1.27.5-v2", Namespace: testNs.Name}
Eventually(func() error {
var openStackNodeImageRelease cspov1alpha1.OpenStackNodeImageRelease
return testEnv.Get(ctx, openstackNodeImageReleaseName, &openStackNodeImageRelease)
}, timeout, interval).Should(BeNil())
})

It("sets ClusterStackReleaseAssetsReadyCondition condition once OpenStackClusterStackRelease object is created", func() {
Eventually(func() bool {
var openStackClusterStackRelease cspov1alpha1.OpenStackClusterStackRelease
return utils.IsPresentAndTrue(ctx, testEnv.Client, openstackClusterStackReleaseKey, &openStackClusterStackRelease, cspov1alpha1.ClusterStackReleaseAssetsReadyCondition)
}, timeout, interval).Should(BeTrue())
})
})
})
3 changes: 1 addition & 2 deletions internal/test/integration/openstack/controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"
"time"

githubclient "github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient/github"
"github.com/SovereignCloudStack/cluster-stack-provider-openstack/internal/controller"
"github.com/SovereignCloudStack/cluster-stack-provider-openstack/internal/test/helpers"
. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -50,7 +49,7 @@ var _ = BeforeSuite(func() {

Expect((&controller.OpenStackClusterStackReleaseReconciler{
Client: testEnv.Manager.GetClient(),
AssetsClientFactory: githubclient.NewFactory(),
AssetsClientFactory: testEnv.AssetsClientFactory,
ReleaseDirectory: "./../../../../test/releases",
}).SetupWithManager(testEnv.Manager)).To(Succeed())

Expand Down
Loading

0 comments on commit 60a59c8

Please sign in to comment.