-
Notifications
You must be signed in to change notification settings - Fork 120
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
Add memory storage for supporting ListAndWatch #345
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5775f70
add a new command for memory storage
wuyingjun-lucky 5c356d3
add deploy manifests for binding_apiserver
duanmengkk 0dcc3b8
add memory storage for save resource in memory
xyz2277 4c5b6b3
complete and optimize the feature for memory storage
duanmengkk 46e794a
encode and save resourceVersion of object in event
wuyingjun-lucky 021c56a
support watch resources with client-go or kubectl
xyz2277 ff20544
code optimization for ListAndWatch
xyz2277 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 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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"k8s.io/apimachinery/pkg/util/runtime" | ||
genericfeatures "k8s.io/apiserver/pkg/features" | ||
cliflag "k8s.io/component-base/cli/flag" | ||
"k8s.io/component-base/cli/globalflag" | ||
"k8s.io/component-base/featuregate" | ||
"k8s.io/component-base/logs" | ||
"k8s.io/component-base/term" | ||
|
||
"github.com/clusterpedia-io/clusterpedia/cmd/apiserver/app/options" | ||
"github.com/clusterpedia-io/clusterpedia/pkg/generated/clientset/versioned" | ||
"github.com/clusterpedia-io/clusterpedia/pkg/synchromanager" | ||
clusterpediafeature "github.com/clusterpedia-io/clusterpedia/pkg/utils/feature" | ||
"github.com/clusterpedia-io/clusterpedia/pkg/version/verflag" | ||
) | ||
|
||
func NewClusterPediaServerCommand(ctx context.Context) *cobra.Command { | ||
opts := options.NewServerOptions() | ||
|
||
cmd := &cobra.Command{ | ||
Use: "clusterpedia-apiserver", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
verflag.PrintAndExitIfRequested() | ||
|
||
// Activate logging as soon as possible, after that | ||
// show flags with the final logging configuration. | ||
if err := opts.Logs.ValidateAndApply(clusterpediafeature.FeatureGate); err != nil { | ||
return err | ||
} | ||
cliflag.PrintFlags(cmd.Flags()) | ||
|
||
config, err := opts.Config() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
completedConfig := config.Complete() | ||
if completedConfig.ClientConfig == nil { | ||
return fmt.Errorf("CompletedConfig.New() called with config.ClientConfig == nil") | ||
} | ||
if completedConfig.StorageFactory == nil { | ||
return fmt.Errorf("CompletedConfig.New() called with config.StorageFactory == nil") | ||
} | ||
|
||
crdclient, err := versioned.NewForConfig(completedConfig.ClientConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
synchromanager := synchromanager.NewManager(crdclient, config.StorageFactory) | ||
go synchromanager.Run(1, ctx.Done()) | ||
|
||
server, err := completedConfig.New() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := server.Run(ctx); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
namedFlagSets := opts.Flags() | ||
verflag.AddFlags(namedFlagSets.FlagSet("global")) | ||
globalflag.AddGlobalFlags(namedFlagSets.FlagSet("global"), cmd.Name(), logs.SkipLoggingConfigurationFlags()) | ||
clusterpediafeature.MutableFeatureGate.AddFlag(namedFlagSets.FlagSet("mutable feature gate")) | ||
|
||
fs := cmd.Flags() | ||
for _, f := range namedFlagSets.FlagSets { | ||
fs.AddFlagSet(f) | ||
} | ||
|
||
cols, _, _ := term.TerminalSize(cmd.OutOrStdout()) | ||
cliflag.SetUsageAndHelpFunc(cmd, namedFlagSets, cols) | ||
return cmd | ||
} | ||
|
||
func init() { | ||
runtime.Must(logs.AddFeatureGates(clusterpediafeature.MutableFeatureGate)) | ||
|
||
// The feature gate `RemainingItemCount` should default to false | ||
// https://github.com/clusterpedia-io/clusterpedia/issues/196 | ||
gates := clusterpediafeature.MutableFeatureGate.GetAll() | ||
gate := gates[genericfeatures.RemainingItemCount] | ||
gate.Default = false | ||
gates[genericfeatures.RemainingItemCount] = gate | ||
|
||
clusterpediafeature.MutableFeatureGate = featuregate.NewFeatureGate() | ||
runtime.Must(clusterpediafeature.MutableFeatureGate.Add(gates)) | ||
clusterpediafeature.FeatureGate = clusterpediafeature.MutableFeatureGate | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
apiserver "k8s.io/apiserver/pkg/server" | ||
"k8s.io/component-base/cli" | ||
_ "k8s.io/component-base/logs/json/register" // for JSON log format registration | ||
|
||
"github.com/clusterpedia-io/clusterpedia/cmd/binding-apiserver/app" | ||
) | ||
|
||
func main() { | ||
ctx := apiserver.SetupSignalContext() | ||
command := app.NewClusterPediaServerCommand(ctx) | ||
code := cli.Run(command) | ||
os.Exit(code) | ||
} |
13 changes: 13 additions & 0 deletions
13
deploy/binding-apiserver/clusterpedia_binding_apiserver_apiservice.yaml
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: apiregistration.k8s.io/v1 | ||
kind: APIService | ||
metadata: | ||
name: v1beta1.clusterpedia.io | ||
spec: | ||
insecureSkipTLSVerify: true | ||
group: clusterpedia.io | ||
groupPriorityMinimum: 1000 | ||
versionPriority: 100 | ||
service: | ||
name: clusterpedia-binding-apiserver | ||
namespace: clusterpedia-system | ||
version: v1beta1 |
45 changes: 45 additions & 0 deletions
45
deploy/binding-apiserver/clusterpedia_binding_apiserver_deployment.yaml
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: clusterpedia-binding-apiserver | ||
namespace: clusterpedia-system | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: clusterpedia-binding-apiserver | ||
namespace: clusterpedia-system | ||
spec: | ||
ports: | ||
- port: 443 | ||
protocol: TCP | ||
targetPort: 443 | ||
selector: | ||
app: clusterpedia-binding-apiserver | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: clusterpedia-binding-apiserver | ||
namespace: clusterpedia-system | ||
labels: | ||
app: clusterpedia-binding-apiserver | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: clusterpedia-binding-apiserver | ||
template: | ||
metadata: | ||
labels: | ||
app: clusterpedia-binding-apiserver | ||
spec: | ||
containers: | ||
- name: binding-apiserver | ||
image: ghcr.io/clusterpedia-io/clusterpedia/binding-apiserver:v0.4.1 | ||
command: | ||
- /usr/local/bin/binding-apiserver | ||
- --secure-port=443 | ||
- --storage-name=memory | ||
- -v=3 | ||
serviceAccountName: clusterpedia-binding-apiserver |
24 changes: 24 additions & 0 deletions
24
deploy/binding-apiserver/clusterpedia_binding_apiserver_rbac.yaml
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: clusterpedia | ||
rules: | ||
- apiGroups: ['*'] | ||
resources: ['*'] | ||
verbs: ["*"] | ||
- nonResourceURLs: ['*'] | ||
verbs: ["get"] | ||
|
||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: clusterpedia | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: clusterpedia | ||
subjects: | ||
- kind: ServiceAccount | ||
name: clusterpedia-binding-apiserver | ||
namespace: clusterpedia-system |
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
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.
I feel that this name is not very good, but I do not have a good suggestion:laughing:, so if there is no better name, we can start with this.