Repository navigation
CNTRLPLANE-3234: health reporter writer #2318
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
Changes from 4 commits
be1b3d3
ca23cdf
e45c7ac
29f822d
4f827b8
6f33b49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,20 +6,21 @@ import ( | |
| "regexp" | ||
| "time" | ||
|
|
||
| "github.com/openshift/library-go/pkg/operator/v1helpers" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/pflag" | ||
|
|
||
| metav1validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" | ||
| "k8s.io/apimachinery/pkg/util/sets" | ||
| "k8s.io/apimachinery/pkg/util/wait" | ||
| "k8s.io/apiserver/pkg/server" | ||
| k8senvelopekmsv2 "k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2" | ||
| "k8s.io/client-go/rest" | ||
| "k8s.io/client-go/tools/clientcmd" | ||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| const Subcommand = "kms-health-reporter" | ||
| const ( | ||
| Subcommand = "kms-health-reporter" | ||
| ) | ||
|
|
||
| // kmsSocketPattern matches the socket path each co-located KMSv2 plugin is | ||
| // mounted at, e.g. unix:///var/run/kmsplugin/kms-1.sock. | ||
|
|
@@ -35,21 +36,20 @@ type options struct { | |
| NodeName string | ||
| Kubeconfig string | ||
|
|
||
| newOperatorClient func(*rest.Config) (v1helpers.OperatorClient, error) | ||
| newWriter NewEncryptionStatusWriterFunc | ||
| } | ||
|
|
||
| type Config struct { | ||
| operatorClient v1helpers.OperatorClient | ||
| prober *prober | ||
| writeStatus EncryptionStatusWriter | ||
| prober *prober | ||
|
|
||
| interval time.Duration | ||
| writeTimeout time.Duration | ||
| nodeName string | ||
| } | ||
|
|
||
| func NewCommand(ctx context.Context, newOperatorClient func(*rest.Config) (v1helpers.OperatorClient, error)) *cobra.Command { | ||
| func NewCommand(ctx context.Context, newWriter NewEncryptionStatusWriterFunc) *cobra.Command { | ||
| o := &options{ | ||
| newOperatorClient: newOperatorClient, | ||
| newWriter: newWriter, | ||
| } | ||
|
|
||
| cmd := &cobra.Command{ | ||
|
|
@@ -114,6 +114,9 @@ func (o *options) validate() error { | |
| if o.NodeName == "" { | ||
| return fmt.Errorf("--node-name is required") | ||
| } | ||
| if fieldManager := fmt.Sprintf("%s-%s", Subcommand, o.NodeName); len(fieldManager) > metav1validation.FieldManagerMaxLength { | ||
| return fmt.Errorf("--node-name too long: reporter identity %q is %d chars, exceeds the %d-char fieldManager limit", fieldManager, len(fieldManager), metav1validation.FieldManagerMaxLength) | ||
|
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. Can we really hit this error?.
Contributor
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. how would you even get out of this situation as an admin? rename your nodes?
Contributor
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. with the prefix we have like 100 characters left, I think it's OK. We can also make the prefix a bit shorter? 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. Maybe we can just continue as is and allow kube-apiserver errors out?
Contributor
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. I think he has a case with this, but we probably need a different solution here checkout the max length we can have per node: 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. I agree with Thomas. If it is possible, maybe we can use something else (uuid, hash, etc.) to remove that check. I think, other than this thread, this PR is ready to merge.
Contributor
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. we can do that as a follow-up. This is probably a bit bigger because we have to rename the cmdline and add this in the lifecycle 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. What about cutting the static length from node name, if it exceeds?
Contributor
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. you'd have to cut the unique bits from the back and hope they don't have a subdomain per node, as Krzys says 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. That makes sense. Thank you |
||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
@@ -126,9 +129,11 @@ func (o *options) Config(ctx context.Context) (*Config, error) { | |
| return nil, fmt.Errorf("build rest config: %w", err) | ||
| } | ||
|
|
||
| operatorClient, err := o.newOperatorClient(restCfg) | ||
| // fieldManager is the per-node ownership identity. | ||
| fieldManager := fmt.Sprintf("%s-%s", Subcommand, o.NodeName) | ||
| writeStatus, err := o.newWriter(restCfg, fieldManager) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("build operator client: %w", err) | ||
| return nil, fmt.Errorf("build encryption status writer: %w", err) | ||
| } | ||
|
|
||
| plugins, err := buildPlugins(ctx, o.KMSSockets, o.ReadTimeout) | ||
|
|
@@ -137,21 +142,24 @@ func (o *options) Config(ctx context.Context) (*Config, error) { | |
| } | ||
|
|
||
| return &Config{ | ||
| operatorClient: operatorClient, | ||
| prober: newProber(plugins), | ||
| interval: o.Interval, | ||
| writeTimeout: o.WriteTimeout, | ||
| nodeName: o.NodeName, | ||
| writeStatus: writeStatus, | ||
| prober: newProber(o.NodeName, plugins), | ||
| interval: o.Interval, | ||
| writeTimeout: o.WriteTimeout, | ||
| }, nil | ||
| } | ||
|
|
||
| func (c *Config) Run(ctx context.Context) error { | ||
| wait.JitterUntilWithContext(ctx, func(ctx context.Context) { | ||
| // Each Status RPC enforces the read timeout internally (set at dial | ||
| // time); ctx here only carries shutdown cancellation. | ||
| conditions := c.prober.probeAll(ctx) | ||
| // TODO: hand conditions to the writer once it lands; logging is a placeholder. | ||
| klog.InfoS("kms plugin health", "conditions", conditions) | ||
| reports := c.prober.probeAll(ctx) | ||
|
|
||
| writeCtx, cancel := context.WithTimeout(ctx, c.writeTimeout) | ||
| defer cancel() | ||
| if err := c.writeStatus(writeCtx, reports); err != nil { | ||
| klog.ErrorS(err, "failed to publish kms plugin health") | ||
| } | ||
| }, c.interval, 0.1, false) | ||
|
|
||
| return nil | ||
|
|
@@ -168,7 +176,7 @@ func buildPlugins(ctx context.Context, sockets []string, timeout time.Duration) | |
|
|
||
| // Unique name per plugin so the gRPC client's KMS operation metrics | ||
| // don't merge both plugins into one series. | ||
| service, err := k8senvelopekmsv2.NewGRPCService(ctx, socket, Subcommand+"-"+keyID, timeout) | ||
| service, err := k8senvelopekmsv2.NewGRPCService(ctx, socket, Subcommand, timeout) | ||
| if err != nil { | ||
| // With the current dependency version this should never happen with a validated GRPC endpoint. | ||
| return nil, fmt.Errorf("setting up grpc service failed at %q: %w", socket, err) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.