chore: cache clearning if CRDs do not exist

This commit is contained in:
eding 2025-11-19 08:36:17 +01:00
parent 87e9c98bf1
commit 85e0a700cb

View file

@ -105,6 +105,11 @@ func runCreateDockerSecret(cmd *cobra.Command, args []string) {
}
func runCreateGhcrSecret(cmd *cobra.Command, args []string) {
if err := k8s.CheckExternalSecretCRD(); err != nil {
fmt.Printf("[ERROR] Prerequisite check failed: %v\n", err)
os.Exit(1)
}
vm, err := vault.NewVaultManager()
if err != nil {
fmt.Printf("[ERROR] Failed to initialize Vault manager: %v\n", err)
@ -134,6 +139,30 @@ func runCreateGhcrSecret(cmd *cobra.Command, args []string) {
fmt.Printf("[ERROR] Failed to store organization management PAT in Vault: %v\n", err)
os.Exit(1)
}
err = k8s.CreateGhcrExternalSecret()
if err == nil {
return
}
if strings.Contains(err.Error(), "no matches for kind") {
cacheCleared := utils.HandleKubectlCacheError(err)
if cacheCleared {
fmt.Println("\n[INFO] Retrying to apply the ExternalSecret after clearing cache...")
time.Sleep(1 * time.Second)
err = k8s.CreateGhcrExternalSecret()
if err == nil {
fmt.Println("[SUCCESS] ExternalSecret applied successfully on the second attempt.")
return
}
}
}
fmt.Printf("\n[ERROR] Operation failed. The secrets are saved in Vault, but the ExternalSecret for GHCR could not be applied to Kubernetes.\n")
fmt.Printf("Final error: %v\n", err)
os.Exit(1)
}
func runCreateGithubSecret(cmd *cobra.Command, args []string) {