This repository was archived by the owner on Dec 3, 2024. It is now read-only.
generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 30
Major refactor and bugfixes #49
Merged
Merged
Changes from all commits
Commits
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 was deleted.
Oops, something went wrong.
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,73 @@ | ||
// Copyright 2021 The Kubernetes Authors. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/provisioner" | ||
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/sampledriver" | ||
|
||
"k8s.io/klog/v2" | ||
) | ||
|
||
const provisionerName = "minio.objectstorage.k8s.io" | ||
|
||
var ( | ||
driverAddress = "unix:///var/lib/cosi/cosi.sock" | ||
) | ||
|
||
var cmd = &cobra.Command{ | ||
Use: "minio-cosi-driver", | ||
Short: "K8s COSI driver for MinIO object storage", | ||
SilenceErrors: true, | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return run(cmd.Context(), args) | ||
}, | ||
DisableFlagsInUseLine: true, | ||
} | ||
|
||
func init() { | ||
viper.AutomaticEnv() | ||
|
||
flag.Set("alsologtostderr", "true") | ||
kflags := flag.NewFlagSet("klog", flag.ExitOnError) | ||
klog.InitFlags(kflags) | ||
|
||
persistentFlags := cmd.PersistentFlags() | ||
persistentFlags.AddGoFlagSet(kflags) | ||
|
||
stringFlag := persistentFlags.StringVarP | ||
stringFlag(&driverAddress, | ||
"driver-addr", | ||
"d", | ||
driverAddress, | ||
"path to unix domain socket where driver should listen") | ||
|
||
viper.BindPFlags(cmd.PersistentFlags()) | ||
} | ||
|
||
func run(ctx context.Context, args []string) error { | ||
identityServer, bucketProvisioner := sampledriver.NewDriver(provisionerName) | ||
server, err := provisioner.NewDefaultCOSIProvisionerServer(driverAddress, identityServer, bucketProvisioner) | ||
if err != nil { | ||
return err | ||
} | ||
return server.Run(ctx) | ||
} |
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,44 @@ | ||
// Copyright 2021 The Kubernetes Authors. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"k8s.io/klog/v2" | ||
) | ||
|
||
func main() { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
sigs := make(chan os.Signal, 1) | ||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
go func() { | ||
sig := <-sigs | ||
klog.InfoS("Signal received", "type", sig) | ||
cancel() | ||
<-time.After(30 * time.Second) | ||
os.Exit(1) | ||
}() | ||
|
||
if err := cmd.ExecuteContext(ctx); err != nil { | ||
klog.ErrorS(err, "Exiting on error") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,101 @@ | ||
/* Copyright 2021 The Kubernetes Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
|
||
"sigs.k8s.io/container-object-storage-interface-api/controller" | ||
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/bucket" | ||
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/bucketaccess" | ||
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/provisioner" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
"k8s.io/klog/v2" | ||
) | ||
|
||
const DefaultProvisionerName = "provisioner.objectstorage.k8s.io" | ||
|
||
var ( | ||
driverAddress = "unix:///var/lib/cosi/cosi.sock" | ||
provisionerName = "" | ||
kubeconfig = "" | ||
debug = false | ||
) | ||
|
||
var cmd = &cobra.Command{ | ||
Use: "objectstorage-sidecar", | ||
Short: "provisioner that interacts with cosi drivers to manage buckets and bucketAccesses", | ||
SilenceErrors: true, | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return run(cmd.Context(), args) | ||
}, | ||
DisableFlagsInUseLine: true, | ||
} | ||
|
||
func init() { | ||
viper.AutomaticEnv() | ||
|
||
flag.Set("alsologtostderr", "true") | ||
kflags := flag.NewFlagSet("klog", flag.ExitOnError) | ||
klog.InitFlags(kflags) | ||
|
||
persistentFlags := cmd.PersistentFlags() | ||
persistentFlags.AddGoFlagSet(kflags) | ||
|
||
stringFlag := persistentFlags.StringVarP | ||
boolFlag := persistentFlags.BoolVarP | ||
|
||
stringFlag(&kubeconfig, "kubeconfig", "", kubeconfig, "path to kubeconfig file") | ||
stringFlag(&driverAddress, "driver-addr", "d", driverAddress, "path to unix domain socket where driver is listening") | ||
stringFlag(&provisionerName, "provisioner", "p", DefaultProvisionerName, "The name of the provisioner") | ||
|
||
boolFlag(&debug, "debug", "g", debug, "Logs all grpc requests and responses") | ||
|
||
viper.BindPFlags(cmd.PersistentFlags()) | ||
} | ||
|
||
func run(ctx context.Context, args []string) error { | ||
if provisionerName == "" { | ||
provisionerName = DefaultProvisionerName | ||
} | ||
|
||
ctrl, err := controller.NewDefaultObjectStorageController("cosi", provisionerName, 40) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we need to move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identity is inferred from ProvisionerGetInfo, and thread count is not something that NEEDS to be configurable yet - it'll cause more confusion than any potential benefits There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good! |
||
if err != nil { | ||
return err | ||
} | ||
|
||
klog.V(3).InfoS("Attempting connection to driver", "address", driverAddress) | ||
cosiClient, err := provisioner.NewDefaultCOSIProvisionerClient(ctx, driverAddress, debug) | ||
if err != nil { | ||
return err | ||
} | ||
klog.V(3).InfoS("Successfully connected to driver") | ||
|
||
ctrl.AddBucketListener(bucket.NewBucketListener(provisionerName, cosiClient)) | ||
|
||
bal, err := bucketaccess.NewBucketAccessListener(provisionerName, cosiClient) | ||
if err != nil { | ||
return err | ||
} | ||
ctrl.AddBucketAccessListener(bal) | ||
|
||
return ctrl.Run(ctx) | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this long of a pause needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a long pause. This is needed in case graceful shutdown doesn;t complete in 30 seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the main thread is expected to exit in these 30 seconds