-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance support for control-plane split
Signed-off-by: Nicolas Bigler <[email protected]>
- Loading branch information
Showing
10 changed files
with
124 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,59 @@ | ||
package webhooks | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
"os" | ||
|
||
"github.com/spf13/viper" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/client-go/tools/clientcmd" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
//+kubebuilder:webhook:verbs=delete,path=/validate--v1-namespace,mutating=false,failurePolicy=fail,groups="",resources=namespaces,versions=v1,name=namespace.vshn.appcat.vshn.io,sideEffects=None,admissionReviewVersions=v1 | ||
|
||
// SetupNamespaceDeletionProtectionHandlerWithManager registers the validation webhook with the manager. | ||
func SetupNamespaceDeletionProtectionHandlerWithManager(mgr ctrl.Manager) error { | ||
cpClient := mgr.GetClient() | ||
if viper.IsSet("CONTROL_PLANE_KUBECONFIG") { | ||
kubeconfigPath := viper.GetString("CONTROL_PLANE_KUBECONFIG") | ||
file, err := os.Open(kubeconfigPath) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
// Get the file size | ||
stat, err := file.Stat() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Read the file into a byte slice | ||
kubeconfig := make([]byte, stat.Size()) | ||
_, err = bufio.NewReader(file).Read(kubeconfig) | ||
if err != nil && err != io.EOF { | ||
return err | ||
} | ||
config, err := clientcmd.RESTConfigFromKubeConfig([]byte(kubeconfig)) | ||
if err != nil { | ||
return nil | ||
} | ||
cpClient, err = client.New(config, client.Options{ | ||
Scheme: mgr.GetScheme(), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(&corev1.Namespace{}). | ||
WithValidator(&GenericDeletionProtectionHandler{ | ||
client: mgr.GetClient(), | ||
log: mgr.GetLogger().WithName("webhook").WithName("namespace"), | ||
client: mgr.GetClient(), | ||
controlPlaneClient: cpClient, | ||
log: mgr.GetLogger().WithName("webhook").WithName("namespace"), | ||
}). | ||
Complete() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters