Partial code comments

Signed-off-by: Tom Proctor <tomhjp@users.noreply.github.com>
This commit is contained in:
Tom Proctor 2024-10-04 19:49:00 +01:00
parent 85ce16b0d6
commit aeb772e615
3 changed files with 9 additions and 17 deletions

View File

@ -42,15 +42,14 @@ import (
const ( const (
reasonProxyGroupCreationFailed = "ProxyGroupCreationFailed" reasonProxyGroupCreationFailed = "ProxyGroupCreationFailed"
reasonProxyGroupCreated = "ProxyGroupCreated" reasonProxyGroupReady = "ProxyGroupReady"
reasonProxyGroupCreating = "ProxyGroupCreating" reasonProxyGroupCreating = "ProxyGroupCreating"
reasonProxyGroupInvalid = "ProxyGroupInvalid" reasonProxyGroupInvalid = "ProxyGroupInvalid"
) )
var gaugeProxyGroupResources = clientmetric.NewGauge(kubetypes.MetricProxyGroupCount) var gaugeProxyGroupResources = clientmetric.NewGauge(kubetypes.MetricProxyGroupCount)
// ProxyGroupReconciler syncs ProxyGroup statefulsets with their definition in // ProxyGroupReconciler ensures cluster resources for a ProxyGroup definition.
// ProxyGroup CRs.
type ProxyGroupReconciler struct { type ProxyGroupReconciler struct {
client.Client client.Client
l *zap.SugaredLogger l *zap.SugaredLogger
@ -155,7 +154,7 @@ func (r *ProxyGroupReconciler) Reconcile(ctx context.Context, req reconcile.Requ
} }
logger.Info("ProxyGroup resources synced") logger.Info("ProxyGroup resources synced")
return setStatusReady(pg, metav1.ConditionTrue, reasonProxyGroupCreated, reasonProxyGroupCreated) return setStatusReady(pg, metav1.ConditionTrue, reasonProxyGroupReady, reasonProxyGroupReady)
} }
func (r *ProxyGroupReconciler) maybeProvision(ctx context.Context, pg *tsapi.ProxyGroup) error { func (r *ProxyGroupReconciler) maybeProvision(ctx context.Context, pg *tsapi.ProxyGroup) error {
@ -172,7 +171,7 @@ func (r *ProxyGroupReconciler) maybeProvision(ctx context.Context, pg *tsapi.Pro
return fmt.Errorf("failed to get ProxyClass: %w", err) return fmt.Errorf("failed to get ProxyClass: %w", err)
} }
if !tsoperator.ProxyClassIsReady(proxyClass) { if !tsoperator.ProxyClassIsReady(proxyClass) {
logger.Infof("ProxyClass %s specified for the proxy, but it is not (yet) in a ready state, waiting...", pg.Spec.ProxyClass) logger.Infof("ProxyClass %s specified for the ProxyGroup, but it is not (yet) in a ready state, waiting...", pg.Spec.ProxyClass)
return nil return nil
} }
} }
@ -267,8 +266,6 @@ func (r *ProxyGroupReconciler) cleanupDanglingResources(ctx context.Context, pg
if !apierrors.IsNotFound(err) { if !apierrors.IsNotFound(err) {
return fmt.Errorf("error deleting state Secret %s: %w", m.stateSecret.Name, err) return fmt.Errorf("error deleting state Secret %s: %w", m.stateSecret.Name, err)
} }
logger.Debugf("deleted state Secret %s but got not found", m.stateSecret.Name)
} }
configSecret := m.stateSecret.DeepCopy() configSecret := m.stateSecret.DeepCopy()
configSecret.Name += "-config" configSecret.Name += "-config"
@ -276,8 +273,6 @@ func (r *ProxyGroupReconciler) cleanupDanglingResources(ctx context.Context, pg
if !apierrors.IsNotFound(err) { if !apierrors.IsNotFound(err) {
return fmt.Errorf("error deleting config Secret %s: %w", configSecret.Name, err) return fmt.Errorf("error deleting config Secret %s: %w", configSecret.Name, err)
} }
logger.Debugf("deleted config Secret %s but got not found", configSecret.Name)
} }
} }
@ -425,10 +420,7 @@ func pgTailscaledConfig(pg *tsapi.ProxyGroup, class *tsapi.ProxyClass, idx int32
conf.AuthKey = key conf.AuthKey = key
} }
capVerConfigs := make(map[tailcfg.CapabilityVersion]ipn.ConfigVAlpha) capVerConfigs := make(map[tailcfg.CapabilityVersion]ipn.ConfigVAlpha)
capVerConfigs[95] = *conf capVerConfigs[106] = *conf
// legacy config should not contain NoStatefulFiltering field.
conf.NoStatefulFiltering.Clear()
capVerConfigs[94] = *conf
return capVerConfigs, nil return capVerConfigs, nil
} }

View File

@ -77,7 +77,7 @@ func TestProxyGroup(t *testing.T) {
TailnetIPs: []string{"1.2.3.4", "::1"}, TailnetIPs: []string{"1.2.3.4", "::1"},
}, },
} }
tsoperator.SetProxyGroupCondition(pg, tsapi.ProxyGroupReady, metav1.ConditionTrue, reasonProxyGroupCreated, reasonProxyGroupCreated, 0, cl, zl.Sugar()) tsoperator.SetProxyGroupCondition(pg, tsapi.ProxyGroupReady, metav1.ConditionTrue, reasonProxyGroupReady, reasonProxyGroupReady, 0, cl, zl.Sugar())
expectEqual(t, fc, pg, nil) expectEqual(t, fc, pg, nil)
expectProxyGroupResources(t, fc, pg, true) expectProxyGroupResources(t, fc, pg, true)
}) })
@ -93,7 +93,7 @@ func TestProxyGroup(t *testing.T) {
addNodeIDToStateSecrets(t, fc, pg) addNodeIDToStateSecrets(t, fc, pg)
expectReconciled(t, reconciler, "", pg.Name) expectReconciled(t, reconciler, "", pg.Name)
tsoperator.SetProxyGroupCondition(pg, tsapi.ProxyGroupReady, metav1.ConditionTrue, reasonProxyGroupCreated, reasonProxyGroupCreated, 0, cl, zl.Sugar()) tsoperator.SetProxyGroupCondition(pg, tsapi.ProxyGroupReady, metav1.ConditionTrue, reasonProxyGroupReady, reasonProxyGroupReady, 0, cl, zl.Sugar())
pg.Status.Devices = append(pg.Status.Devices, tsapi.TailnetDevice{ pg.Status.Devices = append(pg.Status.Devices, tsapi.TailnetDevice{
Hostname: "hostname-nodeid-2", Hostname: "hostname-nodeid-2",
TailnetIPs: []string{"1.2.3.4", "::1"}, TailnetIPs: []string{"1.2.3.4", "::1"},

View File

@ -66,8 +66,8 @@ type ProxyGroupSpec struct {
// ProxyClass is the name of the ProxyClass custom resource that contains // ProxyClass is the name of the ProxyClass custom resource that contains
// configuration options that should be applied to the resources created // configuration options that should be applied to the resources created
// for this ProxyGroup. If unset, and no default ProxyClass is set, the // for this ProxyGroup. If unset, the operator will create resources with
// operator will create resources with the default configuration. // the default configuration.
// +optional // +optional
ProxyClass string `json:"proxyClass,omitempty"` ProxyClass string `json:"proxyClass,omitempty"`
} }