File tree 1 file changed +17
-1
lines changed
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 6
6
"github.com/spf13/cobra"
7
7
"github.com/spf13/pflag"
8
8
"github.com/spf13/viper"
9
+ corev1 "k8s.io/api/core/v1"
10
+ apierrors "k8s.io/apimachinery/pkg/api/errors"
9
11
runtime_ctrl "sigs.k8s.io/controller-runtime"
10
12
"sigs.k8s.io/controller-runtime/pkg/client"
11
13
@@ -82,10 +84,24 @@ func (s *genSecretsCmd) exec(*cobra.Command, []string) error {
82
84
return fmt .Errorf ("client: %w" , err )
83
85
}
84
86
87
+ // Check if secret already exists
88
+ existing := & corev1.Secret {}
89
+ err = c .Get (ctx , * name , existing )
90
+ if err == nil {
91
+ // Secret already exists, exit gracefully
92
+ return nil
93
+ }
94
+ if ! apierrors .IsNotFound (err ) {
95
+ return fmt .Errorf ("check existing secret: %w" , err )
96
+ }
97
+
85
98
secret , err := util .NewBootstrapSecrets (* name )
86
99
if err != nil {
87
100
return fmt .Errorf ("generate secrets: %w" , err )
88
101
}
89
102
90
- return c .Create (ctx , secret )
103
+ if err := c .Create (ctx , secret ); err != nil {
104
+ return fmt .Errorf ("create secret: %w" , err )
105
+ }
106
+ return nil
91
107
}
You can’t perform that action at this time.
0 commit comments