-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Proof of concept of a common plugin base #47972
base: master
Are you sure you want to change the base?
Conversation
This pull request is automatically being deployed by Amplify Hosting (learn more). |
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.
Overall seems like a decent approach
func (a *Launcher) checkTeleportVersion(ctx context.Context) (proto.PingResponse, error) { | ||
pong, err := a.teleportClient.Ping(ctx) | ||
if err != nil { | ||
if trace.IsNotImplemented(err) { | ||
return pong, trace.Wrap(err, "server version must be at least %s", minServerVersion) | ||
} | ||
return pong, trace.Wrap(err, "Unable to get Teleport server version") | ||
} | ||
err = utils.CheckMinVersion(pong.ServerVersion, minServerVersion) | ||
return pong, trace.Wrap(err) | ||
} |
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.
Is this still relevant? The minimum version this would be released in is v15 which seems highly unlikely to be running against a v6 control plane.
return trace.Wrap(err) | ||
} | ||
|
||
a.PluginName = a.Conf.PluginName() |
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 does this need to be updated?
} | ||
|
||
type Service interface { | ||
Run(ctx context.Context, clt teleport.Client, name string /* TODO add status sink */) error |
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.
What does the name here convey? Why does it need to be given to the service?
return wrapAPIClient(clt), nil | ||
} | ||
|
||
// TODO: check if we can get rid of this? |
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.
+1 - Can teleport.Client be updated to use the matching signature so this can be eliminated?
group.Go(func() error { | ||
return service.Run(ctx, a.teleportClient, a.PluginName) | ||
}) | ||
} | ||
|
||
return group.Wait() |
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.
What is the expected behavior if any one of the services fails, causing this to return? Do we expect systemd/kubernetes to restart the plugin?
} | ||
|
||
group, ctx := errgroup.WithContext(ctx) | ||
for _, service := range a.Services { |
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.
Should we warn if there are no services configured?
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package common |
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.
Suggestion: avoid packages like common, utils, helpers, etc.
https://go.dev/wiki/CodeReviewComments#package-names
https://go.dev/doc/effective_go#package-names
type accessListReminderService struct { | ||
// provided on creation | ||
notifier Notifier | ||
clock clockwork.Clock | ||
|
||
// provided at runtime | ||
pluginName string | ||
teleportClient teleport.Client | ||
|
||
// initialized but the service itself | ||
pluginData *pd.CompareAndSwap[pd.AccessListNotificationData] | ||
} | ||
|
||
func NewAccessListReminderService(notifier Notifier) launcher.Service { | ||
return &accessListReminderService{ | ||
notifier: notifier, | ||
clock: clockwork.NewRealClock(), | ||
} | ||
} |
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.
Suggestion: remove the stutter and export the service
https://go.dev/wiki/CodeReviewComments#interfaces
https://go.dev/doc/effective_go#package-names
type accessListReminderService struct { | |
// provided on creation | |
notifier Notifier | |
clock clockwork.Clock | |
// provided at runtime | |
pluginName string | |
teleportClient teleport.Client | |
// initialized but the service itself | |
pluginData *pd.CompareAndSwap[pd.AccessListNotificationData] | |
} | |
func NewAccessListReminderService(notifier Notifier) launcher.Service { | |
return &accessListReminderService{ | |
notifier: notifier, | |
clock: clockwork.NewRealClock(), | |
} | |
} | |
type ReminderService struct { | |
// provided on creation | |
notifier Notifier | |
clock clockwork.Clock | |
// provided at runtime | |
pluginName string | |
teleportClient teleport.Client | |
// initialized but the service itself | |
pluginData *pd.CompareAndSwap[pd.AccessListNotificationData] | |
} | |
func NewReminderService(notifier Notifier) *ReminderService { | |
return &ReminderService{ | |
notifier: notifier, | |
clock: clockwork.NewRealClock(), | |
} | |
} |
a.teleportClient = clt | ||
a.pluginName = name | ||
|
||
a.pluginData = pd.NewCAS( |
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.
Isn't this a bit racy?
type accessRequestService struct { | ||
// provided on creation | ||
notifier Notifier | ||
approvalUser string | ||
staticRecipients common.RawRecipientsMap | ||
|
||
// provided at runtime | ||
pluginName string | ||
teleportClient teleport.Client | ||
|
||
// initialized but the service itself | ||
pluginData *pd.CompareAndSwap[PluginData] | ||
accessMonitoringRules *accessmonitoring.RuleHandler | ||
} | ||
|
||
func NewAccessRequestService(notifier Notifier, staticRecipients common.RawRecipientsMap, approvalUser string) launcher.Service { | ||
return &accessRequestService{ | ||
notifier: notifier, | ||
approvalUser: approvalUser, | ||
staticRecipients: staticRecipients, | ||
} | ||
} |
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.
Same suggestions here as in the other package
type accessRequestService struct { | |
// provided on creation | |
notifier Notifier | |
approvalUser string | |
staticRecipients common.RawRecipientsMap | |
// provided at runtime | |
pluginName string | |
teleportClient teleport.Client | |
// initialized but the service itself | |
pluginData *pd.CompareAndSwap[PluginData] | |
accessMonitoringRules *accessmonitoring.RuleHandler | |
} | |
func NewAccessRequestService(notifier Notifier, staticRecipients common.RawRecipientsMap, approvalUser string) launcher.Service { | |
return &accessRequestService{ | |
notifier: notifier, | |
approvalUser: approvalUser, | |
staticRecipients: staticRecipients, | |
} | |
} | |
type Service struct { | |
// provided on creation | |
notifier Notifier | |
approvalUser string | |
staticRecipients common.RawRecipientsMap | |
// provided at runtime | |
pluginName string | |
teleportClient teleport.Client | |
// initialized but the service itself | |
pluginData *pd.CompareAndSwap[PluginData] | |
accessMonitoringRules *accessmonitoring.RuleHandler | |
} | |
func NewService(notifier Notifier, staticRecipients common.RawRecipientsMap, approvalUser string) *Service { | |
return &Service{ | |
notifier: notifier, | |
approvalUser: approvalUser, | |
staticRecipients: staticRecipients, | |
} | |
} |
No description provided.