Skip to content

Commit

Permalink
✨ Add oci as assets client (#198)
Browse files Browse the repository at this point in the history
* Upgrade CSO dependency to v0.1.0-alpha.6

Signed-off-by: Roman Hros <[email protected]>

* Fix quickstart link

Signed-off-by: Roman Hros <[email protected]>

* Add oci as assets client

Signed-off-by: Roman Hros <[email protected]>

* Try registry.dnation.cloud to fix tests

Signed-off-by: Roman Hros <[email protected]>

* fix(config): use cspo-cluster-stack-variables

Signed-off-by: Jan Schoone <[email protected]>

* feat(envrc): add Resource Sets to sample environment

Signed-off-by: Jan Schoone <[email protected]>

* Add oci username/password to the cspo config

Signed-off-by: Roman Hros <[email protected]>

* feat(tilt): update CAPO version

Signed-off-by: Jan Schoone <[email protected]>

* OCI_USERNAME and OCI_PASSWORD are not required

Signed-off-by: Roman Hros <[email protected]>

* Upgrade CSO dependency to v0.1.0-alpha.7

Signed-off-by: Roman Hros <[email protected]>

* Disable oci integration tests for the GitHub CI

Signed-off-by: Roman Hros <[email protected]>

---------

Signed-off-by: Roman Hros <[email protected]>
Signed-off-by: Jan Schoone <[email protected]>
Co-authored-by: Jan Schoone <[email protected]>
  • Loading branch information
chess-knight and jschoone authored Sep 10, 2024
1 parent 3278995 commit c7a9268
Show file tree
Hide file tree
Showing 1,058 changed files with 85,491 additions and 41,571 deletions.
2 changes: 2 additions & 0 deletions .envrc.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export PATH="$(pwd)/hack/tools/bin/:$PATH"
export KUBECONFIG=$PWD/.mgt-cluster-kubeconfig.yaml
export CLUSTER_TOPOLOGY=true
export EXP_RUNTIME_SDK=true
export EXP_CLUSTER_RESOURCE_SET=true
export CLUSTER_NAME=test-dfkhje
export SECRET_NAME=supersecret
export CLOUD_NAME=test
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ jobs:
GIT_REPOSITORY_NAME: cluster-stacks
GIT_ACCESS_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
ENCODED_CLOUDS_YAML: ${{ secrets.ENCODED_CLOUDS_YAML }}
# OCI_REGISTRY: registry.scs.community
# OCI_REPOSITORY: registry.scs.community/csctl-oci/openstack
run: make test-integration

# - name: Create Report
Expand Down
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ all-tools: get-dependencies $(GOTESTSUM) $(go-cover-treemap) $(go-binsize-treema

env-vars-for-wl-cluster:
ifeq ($(wildcard tilt-settings.yaml),)
@./hack/ensure-env-variables.sh GIT_PROVIDER_B64 GIT_ACCESS_TOKEN_B64 GIT_ORG_NAME_B64 GIT_REPOSITORY_NAME_B64 CLUSTER_TOPOLOGY CLUSTER_NAME SECRET_NAME CLOUD_NAME ENCODED_CLOUDS_YAML
@./hack/ensure-env-variables.sh GIT_PROVIDER_B64 GIT_ACCESS_TOKEN_B64 GIT_ORG_NAME_B64 GIT_REPOSITORY_NAME_B64 CLUSTER_TOPOLOGY EXP_RUNTIME_SDK CLUSTER_NAME SECRET_NAME CLOUD_NAME ENCODED_CLOUDS_YAML
else ifeq ($(shell awk '/local_mode:/ {print tolower($$2)}' tilt-settings.yaml),true)
@./hack/ensure-env-variables.sh CLUSTER_TOPOLOGY CLUSTER_NAME SECRET_NAME CLOUD_NAME ENCODED_CLOUDS_YAML
@./hack/ensure-env-variables.sh CLUSTER_TOPOLOGY EXP_RUNTIME_SDK CLUSTER_NAME SECRET_NAME CLOUD_NAME ENCODED_CLOUDS_YAML
else
@./hack/ensure-env-variables.sh GIT_PROVIDER_B64 GIT_ACCESS_TOKEN_B64 GIT_ORG_NAME_B64 GIT_REPOSITORY_NAME_B64 CLUSTER_TOPOLOGY CLUSTER_NAME SECRET_NAME CLOUD_NAME ENCODED_CLOUDS_YAML
@./hack/ensure-env-variables.sh GIT_PROVIDER_B64 GIT_ACCESS_TOKEN_B64 GIT_ORG_NAME_B64 GIT_REPOSITORY_NAME_B64 CLUSTER_TOPOLOGY EXP_RUNTIME_SDK CLUSTER_NAME SECRET_NAME CLOUD_NAME ENCODED_CLOUDS_YAML
endif

.PHONY: cluster
Expand Down 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
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
4 changes: 2 additions & 2 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ settings = {
"preload_images_for_kind": True,
"kind_cluster_name": "cspo",
"capi_version": "v1.6.0",
"cso_version": "v0.1.0-alpha.5",
"capo_version": "v0.9.0",
"cso_version": "v0.1.0-alpha.7",
"capo_version": "v0.10.4",
"cert_manager_version": "v1.13.2",
"kustomize_substitutions": {
},
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/conditions_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ const (
)

const (
// GitAPIAvailableCondition is used when Git API is available.
GitAPIAvailableCondition = "GitAPIAvailable"
// AssetsClientAPIAvailableCondition is used when AssetsClient API is available.
AssetsClientAPIAvailableCondition = "AssetsClientAPIAvailable"

// GitTokenOrEnvVariableNotSetReason is used when user don't specify the token or environment variable.
GitTokenOrEnvVariableNotSetReason = "GitTokenOrEnvVariableNotSet" //#nosec
// FailedCreateAssetsClientReason is used when user don't specify the token or environment variable required for initializing the assets client.
FailedCreateAssetsClientReason = "FailedCreateAssetsClient" //#nosec
)

const (
Expand Down
27 changes: 20 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +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"

githubclient "github.com/SovereignCloudStack/cluster-stack-operator/pkg/github/client"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/github/client/fake"
"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 @@ -53,6 +56,7 @@ var (
releaseDir string
imageImportTimeout int
localMode bool
source string
metricsAddr string
enableLeaderElection bool
probeAddr string
Expand All @@ -69,7 +73,8 @@ 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 Git repository. Useful for implementing cluster stacks.")
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 @@ -100,18 +105,26 @@ func main() {
// Initialize event recorder.
record.InitFromRecorder(mgr.GetEventRecorderFor("cspo-controller"))

var gitFactory githubclient.Factory
var assetsClientFactory assetsclient.Factory
if localMode {
gitFactory = fake.NewFactory()
assetsClientFactory = fake.NewFactory()
} else {
gitFactory = githubclient.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{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ReleaseDirectory: releaseDir,
GitHubClientFactory: gitFactory,
AssetsClientFactory: assetsClientFactory,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "OpenStackClusterStackRelease")
os.Exit(1)
Expand Down
5 changes: 5 additions & 0 deletions config/manager/credentials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ 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:=""}
oci-username: ${OCI_USERNAME_B64:=""}
oci-password: ${OCI_PASSWORD_B64:=""}
25 changes: 25 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ spec:
secretKeyRef:
name: cspo-cluster-stack-variables
key: git-access-token
- name: OCI_REGISTRY
valueFrom:
secretKeyRef:
name: cspo-cluster-stack-variables
key: oci-registry
- name: OCI_REPOSITORY
valueFrom:
secretKeyRef:
name: cspo-cluster-stack-variables
key: oci-repository
- name: OCI_ACCESS_TOKEN
valueFrom:
secretKeyRef:
name: cspo-cluster-stack-variables
key: oci-access-token
- name: OCI_USERNAME
valueFrom:
secretKeyRef:
name: cspo-cluster-stack-variables
key: oci-username
- name: OCI_PASSWORD
valueFrom:
secretKeyRef:
name: cspo-cluster-stack-variables
key: oci-password
image: controller:latest
name: manager
securityContext:
Expand Down
27 changes: 2 additions & 25 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,6 @@ rules:
- infrastructure.clusterstack.x-k8s.io
resources:
- openstackclusterstackreleases
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- infrastructure.clusterstack.x-k8s.io
resources:
- openstackclusterstackreleases/finalizers
verbs:
- update
- apiGroups:
- infrastructure.clusterstack.x-k8s.io
resources:
- openstackclusterstackreleases/status
verbs:
- get
- patch
- update
- apiGroups:
- infrastructure.clusterstack.x-k8s.io
resources:
- openstacknodeimagereleases
verbs:
- create
Expand All @@ -61,12 +36,14 @@ rules:
- apiGroups:
- infrastructure.clusterstack.x-k8s.io
resources:
- openstackclusterstackreleases/finalizers
- openstacknodeimagereleases/finalizers
verbs:
- update
- apiGroups:
- infrastructure.clusterstack.x-k8s.io
resources:
- openstackclusterstackreleases/status
- openstacknodeimagereleases/status
verbs:
- get
Expand Down
2 changes: 1 addition & 1 deletion docs/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ If you have any trouble finding the right command, then you can use `make help`

## Toggle between local_mode and remote mode

We can retrieve cluster-stacks in two modes. One way is to let the controller fetch it from GitHub which is remote mode and other is we mount the cluster-stacks inside the container at `/tmp/downloads/cluster-stacks` directory.
We can retrieve cluster-stacks in two modes. One way is to let the controller fetch it from repository which is remote mode and other is we mount the cluster-stacks inside the container at `/tmp/downloads/cluster-stacks` directory.

> [!NOTE]
> Using remote mode is the default behavior.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ start;
repeat
:OpenStackClusterStackRelease controller enqueues a Reconcile call;
if (Release assets have been download into the CSPO container) then (no)
:Create GitHub client;
:Create assets client;
#LightBlue:Download Release assets;
#Pink:Return RequeueError;
note left: make sure that Release can be accessed
Expand Down
Binary file modified docs/images/openstackclusterstackrelease-controller.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

This document has been moved.

You can find the current version of the quickstart guide [here](https://docs.scs.community/docs/container/components/cluster-stacks/components/cluster-stack-provider-openstack/docs/quickstart).
You can find the current version of the quickstart guide [here](https://docs.scs.community/docs/container/components/cluster-stacks/components/cluster-stacks/providers/openstack/quickstart).
Loading

0 comments on commit c7a9268

Please sign in to comment.