-
Notifications
You must be signed in to change notification settings - Fork 41
feat: add init container to install fleet CRDs #1141
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 all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
9f26ad0
add sidecar init container to install fleet CRDs
3813c28
use maps
1116fd7
fix make e2e-tests-v1alpha1
84b2d09
minor fix
cb799d5
minor fix
a1f083e
disable crd-installer container by default
533a789
fix Makefile format
87e1fef
fix format
4185de8
update existing CRDs
ee9bd1d
fix v1alpha1 E2E
2669e40
fix crd-installer docker file
17074b5
address Dockerfile comments
387405a
use controllerutil.CreateOrUpdate
2034e88
minor comment fix
6a158d7
add scheme to client
9b7ca7a
check addonmanager label for ownership
a5a133b
lint fix
85be6d1
refactor & add UTs
e10c020
minor changes
2427dc0
remove wait, timeout flags
b9b3add
refactor, expose function to add IT
e32ad18
refactor, add skeleton for IT
8233899
add initial IT
9b3b495
finished IT
36e10a5
move util UT to test directory
7e5f2f8
remove v1alpha1 support from crd-installer
501804a
minor fix
8dbe184
fix UT
f23fd66
minor reverts
0a93201
change IT
927f5a8
refactor IT
99b625b
run tests in pipeline, improve IT
eef2ffa
move UT back to utils
aebcedd
ensure UT is not skipped
58f08bd
lint fix
559d2ea
address comments
9df0d34
minor improvement
86c1a80
use microsoft copyright comment
c35c046
minor changes
5450a4d
remove addon manager label check
bed8448
minor fixes
f679403
add azure managed by label to CRDs
9246062
minor fix
a1337df
address offline comments
38d17f1
use new scheme for IT
8d009ad
fix comments
14abc63
address comments
061372e
move comment
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| 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/cmd/crdinstaller/utils" | ||
| ) | ||
|
|
||
| var ( | ||
| mode = flag.String("mode", "", "Mode to run in: 'hub' or 'member' (required)") | ||
| ) | ||
|
|
||
| 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 CRD installer in %s mode", *mode) | ||
|
|
||
| // 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" | ||
| if err := installCRDs(ctx, client, crdPath, *mode); err != nil { | ||
| klog.Fatalf("Failed to install CRDs: %v", err) | ||
|
ryanzhang-oss marked this conversation as resolved.
|
||
| } | ||
|
|
||
| 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) 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]); 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.