Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 87c2426

Browse files
committed
Add GitHub client and download release assets
Signed-off-by: Roman Hros <[email protected]>
1 parent 3174fbd commit 87c2426

File tree

369 files changed

+80665
-19
lines changed

Some content is hidden

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

369 files changed

+80665
-19
lines changed

Tiltfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def deploy_cspo():
185185
"cspo-leader-election-rolebinding:rolebinding",
186186
"cspo-manager-rolebinding:clusterrolebinding",
187187
#"cspo-serving-cert:certificate",
188-
#"cspo-cluster-stack-variables:secret",
188+
"cspo-cluster-stack-variables:secret",
189189
#"cspo-selfsigned-issuer:issuer",
190190
#"cspo-validating-webhook-configuration:validatingwebhookconfiguration",
191191
],

api/v1alpha1/openstackclusterstackrelease_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package v1alpha1
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21-
2221
apiv1alpha7 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7"
2322
)
2423

api/v1alpha1/openstacknodeimagerelease_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package v1alpha1
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21-
2221
apiv1alpha7 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7"
2322
)
2423

@@ -30,7 +29,7 @@ type OpenStackNodeImageReleaseSpec struct {
3029
// The name of the node image
3130
Name string `json:"name"`
3231
// The URL of the node image
33-
Url string `json:"url"`
32+
URL string `json:"url"`
3433
// The name of the cloud to use from the clouds secret
3534
CloudName string `json:"cloudName"`
3635
// IdentityRef is a reference to a identity to be used when reconciling this cluster

cmd/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"flag"
2222
"os"
2323

24+
githubclient "github.com/SovereignCloudStack/cluster-stack-operator/pkg/github/client"
2425
infrastructureclusterstackxk8siov1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
2526
"github.com/sovereignCloudStack/cluster-stack-provider-openstack/internal/controller"
2627
"k8s.io/apimachinery/pkg/runtime"
@@ -47,6 +48,8 @@ func init() {
4748
//+kubebuilder:scaffold:scheme
4849
}
4950

51+
var releaseDir string
52+
5053
func main() {
5154
var metricsAddr string
5255
var enableLeaderElection bool
@@ -56,6 +59,7 @@ func main() {
5659
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
5760
"Enable leader election for controller manager. "+
5861
"Enabling this will ensure there is only one active controller manager.")
62+
flag.StringVar(&releaseDir, "release-dir", "/tmp/downloads/", "Specify release directory for cluster-stack releases")
5963
opts := zap.Options{
6064
Development: true,
6165
}
@@ -87,9 +91,13 @@ func main() {
8791
os.Exit(1)
8892
}
8993

94+
gitFactory := githubclient.NewFactory()
95+
9096
if err = (&controller.OpenStackClusterStackReleaseReconciler{
91-
Client: mgr.GetClient(),
92-
Scheme: mgr.GetScheme(),
97+
Client: mgr.GetClient(),
98+
Scheme: mgr.GetScheme(),
99+
ReleaseDirectory: releaseDir,
100+
GitHubClientFactory: gitFactory,
93101
}).SetupWithManager(mgr); err != nil {
94102
setupLog.Error(err, "unable to create controller", "controller", "OpenStackClusterStackRelease")
95103
os.Exit(1)

config/manager/credentials.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: cluster-stack-variables
5+
namespace: system
6+
type: Opaque
7+
data:
8+
git-provider: ${GIT_PROVIDER_B64:=""}
9+
git-org-name: ${GIT_ORG_NAME_B64:=""}
10+
git-repo-name: ${GIT_REPOSITORY_NAME_B64:=""}
11+
git-access-token: ${GIT_ACCESS_TOKEN_B64:=""}

config/manager/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
resources:
22
- manager.yaml
3+
- credentials.yaml

config/manager/manager.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ spec:
4141
- /manager
4242
args:
4343
- --leader-elect
44+
env:
45+
- name: GIT_PROVIDER
46+
valueFrom:
47+
secretKeyRef:
48+
name: cspo-cluster-stack-variables
49+
key: git-provider
50+
- name: GIT_ORG_NAME
51+
valueFrom:
52+
secretKeyRef:
53+
name: cspo-cluster-stack-variables
54+
key: git-org-name
55+
- name: GIT_REPOSITORY_NAME
56+
valueFrom:
57+
secretKeyRef:
58+
name: cspo-cluster-stack-variables
59+
key: git-repo-name
60+
- name: GIT_ACCESS_TOKEN
61+
valueFrom:
62+
secretKeyRef:
63+
name: cspo-cluster-stack-variables
64+
key: git-access-token
4465
image: controller:latest
4566
name: manager
4667
securityContext:

go.mod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/sovereignCloudStack/cluster-stack-provider-openstack
33
go 1.21
44

55
require (
6+
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.1
67
github.com/onsi/ginkgo/v2 v2.13.2
78
github.com/onsi/gomega v1.30.0
89
k8s.io/apimachinery v0.28.4
@@ -12,8 +13,10 @@ require (
1213
)
1314

1415
require (
16+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
1517
github.com/beorn7/perks v1.0.1 // indirect
1618
github.com/cespare/xxhash/v2 v2.2.0 // indirect
19+
github.com/cloudflare/circl v1.3.3 // indirect
1720
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1821
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
1922
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
@@ -29,6 +32,8 @@ require (
2932
github.com/golang/protobuf v1.5.3 // indirect
3033
github.com/google/gnostic-models v0.6.8 // indirect
3134
github.com/google/go-cmp v0.6.0 // indirect
35+
github.com/google/go-github/v52 v52.0.0 // indirect
36+
github.com/google/go-querystring v1.1.0 // indirect
3237
github.com/google/gofuzz v1.2.0 // indirect
3338
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
3439
github.com/google/uuid v1.3.1 // indirect
@@ -47,10 +52,10 @@ require (
4752
github.com/prometheus/common v0.44.0 // indirect
4853
github.com/prometheus/procfs v0.11.1 // indirect
4954
github.com/spf13/pflag v1.0.5 // indirect
50-
github.com/stretchr/testify v1.8.4 // indirect
5155
go.uber.org/goleak v1.3.0 // indirect
5256
go.uber.org/multierr v1.11.0 // indirect
5357
go.uber.org/zap v1.25.0 // indirect
58+
golang.org/x/crypto v0.15.0 // indirect
5459
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
5560
golang.org/x/net v0.18.0 // indirect
5661
golang.org/x/oauth2 v0.14.0 // indirect
@@ -70,7 +75,7 @@ require (
7075
k8s.io/component-base v0.28.4 // indirect
7176
k8s.io/klog/v2 v2.100.1 // indirect
7277
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
73-
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
78+
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
7479
sigs.k8s.io/cluster-api v1.6.0 // indirect
7580
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
7681
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect

go.sum

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
2+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
3+
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.1 h1:ZzdupXrOqcm9dtnhbYOnLtkAhIjY6HNGGOYLnEOnAis=
4+
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.1/go.mod h1:CxGwKIWX4KbHRGJYq9eIINr6x6VOPbCXSMsud4whiF8=
15
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
26
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
37
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
48
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
59
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
10+
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
611
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
712
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
813
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
914
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
1015
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
16+
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
17+
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
18+
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
1119
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1220
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1321
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -46,10 +54,15 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
4654
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
4755
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
4856
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
57+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
4958
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
5059
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
5160
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
5261
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
62+
github.com/google/go-github/v52 v52.0.0 h1:uyGWOY+jMQ8GVGSX8dkSwCzlehU3WfdxQ7GweO/JP7M=
63+
github.com/google/go-github/v52 v52.0.0/go.mod h1:WJV6VEEUPuMo5pXqqa2ZCZEdbQqua4zAk2MZTIo+m+4=
64+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
65+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
5366
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
5467
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
5568
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -104,8 +117,8 @@ github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdO
104117
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
105118
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
106119
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
107-
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
108-
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
120+
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
121+
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
109122
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
110123
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
111124
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -135,7 +148,10 @@ go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk=
135148
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
136149
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
137150
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
151+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
138152
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
153+
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
154+
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
139155
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
140156
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
141157
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
@@ -150,6 +166,7 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR
150166
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
151167
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
152168
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
169+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
153170
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
154171
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
155172
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
@@ -170,6 +187,7 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
170187
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
171188
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
172189
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
190+
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
173191
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
174192
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
175193
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
@@ -230,8 +248,8 @@ k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
230248
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
231249
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ=
232250
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM=
233-
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk=
234-
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
251+
k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU=
252+
k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
235253
sigs.k8s.io/cluster-api v1.6.0 h1:2bhVSnUbtWI8taCjd9lGiHExsRUpKf7Z1fXqi/IwYx4=
236254
sigs.k8s.io/cluster-api v1.6.0/go.mod h1:LB7u/WxiWj4/bbpHNOa1oQ8nq0MQ5iYlD0pGfRSBGLI=
237255
sigs.k8s.io/cluster-api-provider-openstack v0.9.0 h1:ScwZIfT1kI88+qMzeO7ppMP9DvEzrfLHuYPg2p1mcho=

internal/controller/openstackclusterstackrelease_controller.go

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ package controller
1818

1919
import (
2020
"context"
21+
"fmt"
22+
"net/http"
23+
"os"
24+
"sync"
25+
"time"
2126

27+
githubclient "github.com/SovereignCloudStack/cluster-stack-operator/pkg/github/client"
28+
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/release"
2229
apiv1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
2330
"k8s.io/apimachinery/pkg/runtime"
2431
ctrl "sigs.k8s.io/controller-runtime"
@@ -29,7 +36,10 @@ import (
2936
// OpenStackClusterStackReleaseReconciler reconciles a OpenStackClusterStackRelease object.
3037
type OpenStackClusterStackReleaseReconciler struct {
3138
client.Client
32-
Scheme *runtime.Scheme
39+
Scheme *runtime.Scheme
40+
GitHubClientFactory githubclient.Factory
41+
ReleaseDirectory string
42+
openStackClusterStackRelDownloadDirectoryMutex sync.Mutex
3343
}
3444

3545
//+kubebuilder:rbac:groups=infrastructure.clusterstack.x-k8s.io,resources=openstackclusterstackreleases,verbs=get;list;watch;create;update;patch;delete
@@ -46,16 +56,75 @@ type OpenStackClusterStackReleaseReconciler struct {
4656
// For more details, check Reconcile and its Result here:
4757
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
4858
func (r *OpenStackClusterStackReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
49-
_ = log.FromContext(ctx)
59+
logger := log.FromContext(ctx)
5060

5161
openstackclusterstackrelease := &apiv1alpha1.OpenStackClusterStackRelease{}
52-
_ = r.Client.Get(ctx, req.NamespacedName, openstackclusterstackrelease)
62+
err := r.Client.Get(ctx, req.NamespacedName, openstackclusterstackrelease)
63+
if err != nil {
64+
return ctrl.Result{}, fmt.Errorf("failed to get OpenStackClusterStackRelease %s/%s: %w", req.Namespace, req.Name, err)
65+
}
5366

54-
// TODO(user): your logic here
67+
gc, err := r.GitHubClientFactory.NewClient(ctx)
68+
if err != nil {
69+
return ctrl.Result{}, fmt.Errorf("failed to create Github client: %w", err)
70+
}
71+
72+
// name of OpenStackClusterStackRelease object is same as the release tag
73+
releaseTag := openstackclusterstackrelease.Name
74+
75+
releaseAssets, download, err := release.New(releaseTag, r.ReleaseDirectory)
76+
if err != nil {
77+
return ctrl.Result{RequeueAfter: 1 * time.Minute}, fmt.Errorf("failed to create release: %w", err)
78+
}
79+
80+
if download {
81+
// this is the point where we download the release from github
82+
// acquire lock so that only one reconcile loop can download the release
83+
r.openStackClusterStackRelDownloadDirectoryMutex.Lock()
84+
85+
if err := downloadReleaseAssets(ctx, releaseTag, releaseAssets.LocalDownloadPath, gc); err != nil {
86+
return ctrl.Result{}, fmt.Errorf("failed to download release assets: %w", err)
87+
}
88+
89+
r.openStackClusterStackRelDownloadDirectoryMutex.Unlock()
90+
91+
// requeue to make sure release assets can be accessed
92+
return ctrl.Result{Requeue: true}, nil
93+
}
94+
95+
logger.Info("OpenStackClusterStackRelease status", "ready", openstackclusterstackrelease.Status.Ready)
96+
openstackclusterstackrelease.Status.Ready = true
97+
err = r.Status().Update(ctx, openstackclusterstackrelease)
98+
if err != nil {
99+
return ctrl.Result{}, fmt.Errorf("failed to update OpenStackClusterStackRelease status")
100+
}
101+
logger.Info("OpenStackClusterStackRelease ready")
55102

56103
return ctrl.Result{}, nil
57104
}
58105

106+
func downloadReleaseAssets(ctx context.Context, releaseTag, downloadPath string, gc githubclient.Client) error {
107+
repoRelease, resp, err := gc.GetReleaseByTag(ctx, releaseTag)
108+
if err != nil {
109+
return fmt.Errorf("failed to fetch release tag %q: %w", releaseTag, err)
110+
}
111+
if resp.StatusCode != http.StatusOK {
112+
return fmt.Errorf("failed to fetch release tag %s with status code %d", releaseTag, resp.StatusCode)
113+
}
114+
115+
assetlist := []string{"metadata.yaml", "node-images.yaml"}
116+
117+
if err := gc.DownloadReleaseAssets(ctx, repoRelease, downloadPath, assetlist); err != nil {
118+
// if download failed for some reason, delete the release directory so that it can be retried in the next reconciliation
119+
if err := os.RemoveAll(downloadPath); err != nil {
120+
return fmt.Errorf("failed to remove release: %w", err)
121+
}
122+
return fmt.Errorf("failed to download release assets: %w", err)
123+
}
124+
125+
return nil
126+
}
127+
59128
// SetupWithManager sets up the controller with the Manager.
60129
func (r *OpenStackClusterStackReleaseReconciler) SetupWithManager(mgr ctrl.Manager) error {
61130
return ctrl.NewControllerManagedBy(mgr).

0 commit comments

Comments
 (0)