Skip to content

Commit 1df577e

Browse files
committed
create secretshare CR
1 parent 129c558 commit 1df577e

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

controllers/bootstrap/init.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package bootstrap
1919
import (
2020
"context"
2121
"strconv"
22+
"strings"
2223
"time"
2324

2425
olmv1 "github.com/operator-framework/api/pkg/operators/v1"
@@ -420,6 +421,33 @@ func (b *Bootstrap) CreateNsScopeConfigmap() error {
420421
return nil
421422
}
422423

424+
// CreateSecretshareCR creates a secretshare CR for sharing the entitlement key
425+
func (b *Bootstrap) CreateSecretshareCR(namespace, masterNamespace string) {
426+
klog.Info("Creating secretshare CR for entitlement registry secret")
427+
dc := discovery.NewDiscoveryClientForConfigOrDie(b.Config)
428+
for {
429+
exist, err := resourceExists(dc, "ibmcpcs.ibm.com/v1", "SecretShare")
430+
if err != nil {
431+
klog.Error(err)
432+
time.Sleep(20 * time.Second)
433+
continue
434+
}
435+
if !exist {
436+
klog.Info("Waiting for SecretShare CRD deployed")
437+
time.Sleep(20 * time.Second)
438+
continue
439+
}
440+
entitlementCR := strings.ReplaceAll(constant.SecretshareEntitlementCR, "CR_NAMESPACE", namespace)
441+
entitlementCR = strings.ReplaceAll(entitlementCR, "MASTER_NAMESPACE", masterNamespace)
442+
if err := b.createOrUpdateFromYaml([]byte(entitlementCR)); err != nil {
443+
klog.Error(err)
444+
time.Sleep(20 * time.Second)
445+
continue
446+
}
447+
break
448+
}
449+
}
450+
423451
func (b *Bootstrap) deleteSubscription(name, namespace string) error {
424452
key := types.NamespacedName{Name: name, Namespace: namespace}
425453
sub := &olmv1alpha1.Subscription{}

controllers/constant/secretshare.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,17 @@ spec:
229229
memory: 200Mi
230230
terminationGracePeriodSeconds: 10
231231
`
232+
233+
// Secretshare Operator CR for entitle registry
234+
const SecretshareEntitlementCR = `
235+
apiVersion: ibmcpcs.ibm.com/v1
236+
kind: SecretShare
237+
metadata:
238+
name: ibm-entitlement-key
239+
namespace: CR_NAMESPACE
240+
spec:
241+
secretshares:
242+
- secretname: ibm-entitlement-key
243+
sharewith:
244+
- namespace: MASTER_NAMESPACE
245+
`

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.13
55
require (
66
github.com/IBM/ibm-namespace-scope-operator v1.0.1
77
github.com/ghodss/yaml v1.0.0
8-
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
8+
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
99
github.com/onsi/ginkgo v1.12.1
1010
github.com/onsi/gomega v1.10.1
1111
github.com/operator-framework/api v0.3.10

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ func main() {
105105
klog.Errorf("Failed to create Namespace Scope ConfigMap: %v", err)
106106
os.Exit(1)
107107
}
108+
109+
go bs.CreateSecretshareCR(operatorNs, bs.MasterNamespace)
108110
}
109111

110112
if operatorNs == bs.MasterNamespace || operatorNs == constant.ClusterOperatorNamespace {

0 commit comments

Comments
 (0)