Skip to content

Commit 621fbb8

Browse files
STONEBLD-1354 Create image repo automatically
1 parent 0445271 commit 621fbb8

File tree

12 files changed

+809
-17
lines changed

12 files changed

+809
-17
lines changed

cmd/controller/main.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import (
44
"flag"
55
zap2 "go.uber.org/zap"
66
"go.uber.org/zap/zapcore"
7+
"io/ioutil"
8+
"net/http"
79
"os"
10+
"strings"
11+
812
// needed for hack/update-codegen.sh
913
_ "k8s.io/code-generator"
1014

@@ -15,6 +19,7 @@ import (
1519

1620
//+kubebuilder:scaffold:imports
1721
"github.com/go-logr/logr"
22+
"github.com/redhat-appstudio/image-controller/pkg/quay"
1823
"github.com/redhat-appstudio/jvm-build-service/pkg/controller"
1924
"github.com/redhat-appstudio/jvm-build-service/pkg/reconciler/util"
2025
)
@@ -52,8 +57,23 @@ func main() {
5257
restConfig := ctrl.GetConfigOrDie()
5358
klog.SetLogger(mainLog)
5459

60+
tokenPath := "/workspace/quaytoken"
61+
tokenContent, err := ioutil.ReadFile(tokenPath)
62+
if err != nil {
63+
mainLog.Error(err, "unable to read quay token")
64+
}
65+
orgPath := "/workspace/organization"
66+
orgContent, err := ioutil.ReadFile(orgPath)
67+
if err != nil {
68+
mainLog.Error(err, "unable to read quay organization")
69+
}
70+
var quayClient *quay.QuayClient
71+
if orgContent != nil && tokenContent != nil {
72+
client := quay.NewQuayClient(&http.Client{Transport: &http.Transport{}}, strings.TrimSpace(string(tokenContent)), "https://quay.io/api/v1")
73+
quayClient = &client
74+
}
75+
5576
var mgr ctrl.Manager
56-
var err error
5777
mopts := ctrl.Options{
5878
MetricsBindAddress: metricsAddr,
5979
Port: 9443,
@@ -65,7 +85,7 @@ func main() {
6585
util.ImageTag = os.Getenv("IMAGE_TAG")
6686
util.ImageRepo = os.Getenv("IMAGE_REPO")
6787

68-
mgr, err = controller.NewManager(restConfig, mopts)
88+
mgr, err = controller.NewManager(restConfig, mopts, quayClient, string(orgContent))
6989
if err != nil {
7090
mainLog.Error(err, "unable to start manager")
7191
os.Exit(1)

deploy/operator/base/deployment.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ spec:
1313
labels:
1414
app: hacbs-jvm-operator
1515
spec:
16+
volumes:
17+
- name: quaytoken
18+
secret:
19+
optional: true
20+
secretName: quaytoken
1621
containers:
1722
- name: hacbs-jvm-operator
1823
image: hacbs-jvm-operator
@@ -30,4 +35,8 @@ spec:
3035
limits:
3136
memory: "512Mi"
3237
cpu: "500m"
38+
volumeMounts:
39+
- mountPath: "/workspace"
40+
name: quaytoken
41+
readOnly: true
3342
serviceAccountName: hacbs-jvm-operator

deploy/operator/base/rbac.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,18 @@ rules:
102102
resourceNames:
103103
- jvm-build-image-secrets
104104
- jvm-build-git-secrets
105+
verbs:
106+
- update
107+
- patch
108+
- delete
109+
- apiGroups:
110+
- ""
111+
# note - tekton gives its controller read access to secrets, so any pods there can access secrets in the pods namespace
112+
resources:
113+
- secrets
105114
verbs:
106115
- get
116+
- create
107117
- apiGroups:
108118
- "apps"
109119
resources:

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ require (
2525
require (
2626
github.com/CycloneDX/cyclonedx-go v0.7.0
2727
github.com/google/go-containerregistry v0.12.0
28+
github.com/redhat-appstudio/image-controller v0.0.0-20230606065013-5c7c65e0db05
2829
github.com/redhat-appstudio/service-provider-integration-operator v0.9.1-0.20230420083506-cd7210b05b60
2930
go.uber.org/zap v1.24.0
3031
)

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:Fecb
284284
github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw=
285285
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
286286
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
287+
github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE=
288+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
287289
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
288290
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
289291
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
@@ -454,6 +456,8 @@ github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJf
454456
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
455457
github.com/prometheus/statsd_exporter v0.21.0 h1:hA05Q5RFeIjgwKIYEdFd59xu5Wwaznf33yKI+pyX6T8=
456458
github.com/prometheus/statsd_exporter v0.21.0/go.mod h1:rbT83sZq2V+p73lHhPZfMc3MLCHmSHelCh9hSGYNLTQ=
459+
github.com/redhat-appstudio/image-controller v0.0.0-20230606065013-5c7c65e0db05 h1:g6fNvu8CLGgPdlmJtvcIAAxztS1IULFyVaOpJ2vyZP4=
460+
github.com/redhat-appstudio/image-controller v0.0.0-20230606065013-5c7c65e0db05/go.mod h1:6v+OpSt2oy3uuP16s4HUdShE9CR5HBSwwjL1fvbkKcg=
457461
github.com/redhat-appstudio/service-provider-integration-operator v0.9.1-0.20230420083506-cd7210b05b60 h1:Ga3vX9OSXwEpsHP+o+UMdFvl0nefSvb9aLE0o6N4lSs=
458462
github.com/redhat-appstudio/service-provider-integration-operator v0.9.1-0.20230420083506-cd7210b05b60/go.mod h1:N5YplXwOfhGK7hKq446zIHYPW6mbLeStvYkoPCcOCGs=
459463
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=

pkg/controller/controller.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package controller
33
import (
44
"context"
55
"fmt"
6+
"github.com/redhat-appstudio/image-controller/pkg/quay"
67
"github.com/redhat-appstudio/jvm-build-service/pkg/metrics"
78
"k8s.io/apimachinery/pkg/labels"
89
"k8s.io/apimachinery/pkg/selection"
@@ -34,7 +35,7 @@ var (
3435
controllerLog = ctrl.Log.WithName("controller")
3536
)
3637

37-
func NewManager(cfg *rest.Config, options ctrl.Options) (ctrl.Manager, error) {
38+
func NewManager(cfg *rest.Config, options ctrl.Options, quayClient *quay.QuayClient, quayOrgName string) (ctrl.Manager, error) {
3839

3940
// we have seen in e2e testing that this path can get invoked prior to the TaskRun CRD getting generated,
4041
// and controller-runtime does not retry on missing CRDs.
@@ -134,7 +135,7 @@ func NewManager(cfg *rest.Config, options ctrl.Options) (ctrl.Manager, error) {
134135
return nil, err
135136
}
136137

137-
if err := jbsconfig.SetupNewReconcilerWithManager(mgr, spiPresent); err != nil {
138+
if err := jbsconfig.SetupNewReconcilerWithManager(mgr, spiPresent, quayClient, quayOrgName); err != nil {
138139
return nil, err
139140
}
140141

pkg/reconciler/jbsconfig/controller.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package jbsconfig
22

33
import (
4+
"github.com/redhat-appstudio/image-controller/pkg/quay"
45
"github.com/redhat-appstudio/jvm-build-service/pkg/apis/jvmbuildservice/v1alpha1"
56
"github.com/redhat-appstudio/service-provider-integration-operator/api/v1beta1"
67
ctrl "sigs.k8s.io/controller-runtime"
78
"sigs.k8s.io/controller-runtime/pkg/handler"
89
"sigs.k8s.io/controller-runtime/pkg/source"
910
)
1011

11-
func SetupNewReconcilerWithManager(mgr ctrl.Manager, spiPresent bool) error {
12-
r := newReconciler(mgr, spiPresent)
12+
func SetupNewReconcilerWithManager(mgr ctrl.Manager, spiPresent bool, quayClient *quay.QuayClient, quayOrgName string) error {
13+
r := newReconciler(mgr, spiPresent, quayClient, quayOrgName)
1314
builder := ctrl.NewControllerManagedBy(mgr).
1415
For(&v1alpha1.JBSConfig{})
1516
if spiPresent {

0 commit comments

Comments
 (0)