Skip to content

Commit

Permalink
Replacing os exit with klog exit
Browse files Browse the repository at this point in the history
Signed-off-by: rchikatw <[email protected]>
  • Loading branch information
rchikatw committed Mar 3, 2024
1 parent 3275b87 commit e8be311
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions onboarding-validation-keys-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"os"

v1 "github.com/red-hat-storage/ocs-operator/api/v4/v1"
"github.com/red-hat-storage/ocs-operator/v4/controllers/util"
Expand All @@ -30,22 +29,19 @@ const (
func main() {
cl, err := newClient()
if err != nil {
klog.Errorf("failed to create clientset: %v", err)
os.Exit(1)
klog.Exitf("failed to create client: %v", err)
}

ctx := context.Background()
operatorNamespace, err := util.GetOperatorNamespace()
if err != nil {
klog.Errorf("unable to get operator namespace: %v", err)
os.Exit(1)
klog.Exitf("unable to get operator namespace: %v", err)
}

// Generate RSA key.
privateKey, err := rsa.GenerateKey(rand.Reader, 4096)
if err != nil {
klog.Errorf("unable to generate private: %v", err)
os.Exit(1)
klog.Exitf("unable to generate private key: %v", err)
}

publicKey := &privateKey.PublicKey
Expand All @@ -69,8 +65,7 @@ func main() {
privateSecret.Namespace = operatorNamespace
err = cl.Delete(ctx, privateSecret)
if err != nil && !kerrors.IsNotFound(err) {
klog.Errorf("failed to delete private secret: %v", err)
os.Exit(1)
klog.Exitf("failed to delete private secret: %v", err)
}

// Delete public key secret
Expand All @@ -79,13 +74,12 @@ func main() {
publicSecret.Namespace = operatorNamespace
err = cl.Delete(ctx, publicSecret)
if err != nil && !kerrors.IsNotFound(err) {
klog.Errorf("failed to delete public secret: %v", err)
os.Exit(1)
klog.Exitf("failed to delete public secret: %v", err)
}

err = controllerutil.SetOwnerReference(storageCluster, privateSecret, cl.Scheme())
if err != nil {
klog.Exitf("failed to set owner reference for privateSecret : %v", err)
klog.Exitf("failed to set owner reference for private secret: %v", err)
}

privateSecret.StringData = map[string]string{
Expand All @@ -94,23 +88,20 @@ func main() {

err = cl.Create(ctx, privateSecret, &client.CreateOptions{})
if err != nil {
klog.Errorf("failed to create private secret: %v", err)
os.Exit(1)
klog.Exitf("failed to create private secret: %v", err)
}

err = controllerutil.SetOwnerReference(storageCluster, publicSecret, cl.Scheme())
if err != nil {
klog.Errorf("failed to create public secret: %v", err)
os.Exit(1)
klog.Exitf("failed to set owner reference for public secret: %v", err)
}
publicSecret.StringData = map[string]string{
"key": publicPem,
}

err = cl.Create(ctx, publicSecret, &client.CreateOptions{})
if err != nil {
klog.Errorf("failed to create public secret: %v", err)
os.Exit(1)
klog.Exitf("failed to create public secret: %v", err)
}

}
Expand Down

0 comments on commit e8be311

Please sign in to comment.