Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create secretshare CR #389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions controllers/bootstrap/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package bootstrap
import (
"context"
"strconv"
"strings"
"time"

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

// CreateSecretshareCR creates a secretshare CR for sharing the entitlement key
func (b *Bootstrap) CreateSecretshareCR(namespace, masterNamespace string) {
klog.Info("Creating secretshare CR for entitlement registry secret")
dc := discovery.NewDiscoveryClientForConfigOrDie(b.Config)
for {
exist, err := resourceExists(dc, "ibmcpcs.ibm.com/v1", "SecretShare")
if err != nil {
klog.Error(err)
time.Sleep(20 * time.Second)
continue
}
if !exist {
klog.Info("Waiting for SecretShare CRD deployed")
time.Sleep(20 * time.Second)
continue
}
entitlementCR := strings.ReplaceAll(constant.SecretshareEntitlementCR, "CR_NAMESPACE", namespace)
entitlementCR = strings.ReplaceAll(entitlementCR, "MASTER_NAMESPACE", masterNamespace)
if err := b.createOrUpdateFromYaml([]byte(entitlementCR)); err != nil {
klog.Error(err)
time.Sleep(20 * time.Second)
continue
}
break
}
}

func (b *Bootstrap) deleteSubscription(name, namespace string) error {
key := types.NamespacedName{Name: name, Namespace: namespace}
sub := &olmv1alpha1.Subscription{}
Expand Down
14 changes: 14 additions & 0 deletions controllers/constant/secretshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,17 @@ spec:
memory: 200Mi
terminationGracePeriodSeconds: 10
`

// Secretshare Operator CR for entitle registry
const SecretshareEntitlementCR = `
apiVersion: ibmcpcs.ibm.com/v1
kind: SecretShare
metadata:
name: ibm-entitlement-key
namespace: CR_NAMESPACE
spec:
secretshares:
- secretname: ibm-entitlement-key
sharewith:
- namespace: MASTER_NAMESPACE
`
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.13
require (
github.com/IBM/ibm-namespace-scope-operator v1.0.1
github.com/ghodss/yaml v1.0.0
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/onsi/ginkgo v1.12.1
github.com/onsi/gomega v1.10.1
github.com/operator-framework/api v0.3.10
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func main() {
klog.Errorf("Failed to create Namespace Scope ConfigMap: %v", err)
os.Exit(1)
}

go bs.CreateSecretshareCR(operatorNs, bs.MasterNamespace)
}

if operatorNs == bs.MasterNamespace || operatorNs == constant.ClusterOperatorNamespace {
Expand Down