-
Notifications
You must be signed in to change notification settings - Fork 19
feat: CRD installer init container #325
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
Merged
Merged
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
2d52163
initial commit
40fc7cb
minor changes
810c2d2
add UT
eec7ec8
add init container to agent charts
2b9b7fe
update bootstrap script to use crd-installer
476ad16
minor changes
9b8aa73
update makefile
ac70f92
collect init container logs
88b44b4
add exclude CRDs logic
9ccea55
use A-series VMs
13a4c87
fix hub exclusion logic
b7441f2
specify platform when building app docker image
69c818d
add flag to control adding azure managed label to CRDs
f18aa04
add ITs
24de6af
make reviewable
73c3881
change to inclusion logic for member
a6901fe
minor fixes
dd17873
add license comment
123a93e
fix conditional check to cover entire initContainers section
e7c53a3
fix comment
f5aea9d
add check to ensure yq exists
6710818
address comments
d884863
address comment
d99930c
add hub exclusion logic for MCS
87fe1c5
address comments
1ca335b
address comments
f5d7461
fix make integration-test
422324b
fix comments
8faf8bf
fix comments
4363e49
address comment
96120a7
remove exclusion logic for hub cluster
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /* | ||
| Copyright (c) Microsoft Corporation. | ||
| Licensed under the MIT license. | ||
| */ | ||
|
|
||
| // Package main contains the CRD installer utility for KubeFleet. | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "flag" | ||
| "fmt" | ||
|
|
||
| apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/klog/v2" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
|
|
||
| "go.goms.io/fleet-networking/cmd/net-crd-installer/utils" | ||
| ) | ||
|
|
||
| var ( | ||
| mode = flag.String("mode", "", "Mode to run in: 'hub' or 'member' (required)") | ||
| isE2ETest = flag.Bool("e2e-test", false, "Whether this is running as part of E2E tests (default: false)") | ||
| ) | ||
|
|
||
| func main() { | ||
| klog.InitFlags(nil) | ||
| flag.Parse() | ||
|
|
||
| // Validate required flags. | ||
| if *mode != "hub" && *mode != "member" { | ||
| klog.Fatal("--mode flag must be either 'hub' or 'member'") | ||
| } | ||
|
|
||
| klog.Infof("Starting network CRD installer in %s mode", *mode) | ||
| klog.Infof("E2E test mode: %t", *isE2ETest) | ||
|
|
||
| // Print all flags for debugging. | ||
| flag.VisitAll(func(f *flag.Flag) { | ||
| klog.V(2).InfoS("flag:", "name", f.Name, "value", f.Value) | ||
| }) | ||
|
|
||
| // Set up controller-runtime logger. | ||
| ctrl.SetLogger(zap.New(zap.UseDevMode(true))) | ||
|
|
||
| // Create context for API operations. | ||
| ctx := ctrl.SetupSignalHandler() | ||
|
|
||
| // Get Kubernetes config using controller-runtime. | ||
| config := ctrl.GetConfigOrDie() | ||
|
|
||
| // Create a scheme that knows about CRD types. | ||
| scheme := runtime.NewScheme() | ||
| if err := apiextensionsv1.AddToScheme(scheme); err != nil { | ||
| klog.Fatalf("Failed to add apiextensions scheme: %v", err) | ||
| } | ||
| client, err := client.New(config, client.Options{ | ||
| Scheme: scheme, | ||
| }) | ||
|
|
||
| if err != nil { | ||
| klog.Fatalf("Failed to create Kubernetes client: %v", err) | ||
| } | ||
|
|
||
| // Install CRDs from the fixed location. | ||
| const crdPath = "/workspace/config/crd/bases" | ||
Arvindthiru marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if err := installCRDs(ctx, client, crdPath, *mode, *isE2ETest); err != nil { | ||
| klog.Fatalf("Failed to install CRDs: %v", err) | ||
| } | ||
|
|
||
| klog.Infof("Successfully installed %s CRDs", *mode) | ||
| } | ||
|
|
||
| // installCRDs installs the CRDs from the specified directory based on the mode. | ||
| func installCRDs(ctx context.Context, client client.Client, crdPath, mode string, isE2ETest bool) error { | ||
| // List of CRDs to install based on mode. | ||
| crdsToInstall, err := utils.CollectCRDs(crdPath, mode, client.Scheme()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if len(crdsToInstall) == 0 { | ||
| return fmt.Errorf("no CRDs found for mode %s in directory %s", mode, crdPath) | ||
| } | ||
|
|
||
| klog.Infof("Found %d CRDs to install for mode %s", len(crdsToInstall), mode) | ||
|
|
||
| // Install each CRD. | ||
| for i := range crdsToInstall { | ||
| if err := utils.InstallCRD(ctx, client, &crdsToInstall[i], isE2ETest); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.