Skip to content

Commit

Permalink
Merge pull request #33 from rfranzke/enh/export
Browse files Browse the repository at this point in the history
Export types to make them reusable for other packages
  • Loading branch information
Amshuman K R authored Jun 22, 2021
2 parents d304f53 + 0087248 commit 2cd8f69
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 22 deletions.
6 changes: 3 additions & 3 deletions pkg/restarter/restarter.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ func (c *Controller) processEndpoint(ctx context.Context, key string) error {
return nil
}

func (c *Controller) shootPodsIfNecessary(ctx context.Context, namespace string, srv service) error {
func (c *Controller) shootPodsIfNecessary(ctx context.Context, namespace string, srv Service) error {
for _, dependantPod := range srv.Dependants {
go func(depPods dependantPods) {
go func(depPods DependantPods) {
err := c.shootDependentPodsIfNecessary(ctx, namespace, &depPods)
if err != nil {
klog.Errorf("Error processing dependents pods: %s", err)
Expand All @@ -248,7 +248,7 @@ func (c *Controller) shootPodsIfNecessary(ctx context.Context, namespace string,
return nil
}

func (c *Controller) shootDependentPodsIfNecessary(ctx context.Context, namespace string, depPods *dependantPods) error {
func (c *Controller) shootDependentPodsIfNecessary(ctx context.Context, namespace string, depPods *DependantPods) error {
selector, err := metav1.LabelSelectorAsSelector(depPods.Selector)
if err != nil {
return fmt.Errorf("error converting label selector to selector %s", depPods.Selector.String())
Expand Down
10 changes: 6 additions & 4 deletions pkg/restarter/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ type Controller struct {
// ServiceDependants holds the service and the label selectors of the pods which has to be restarted when
// the service becomes ready and the pods are in CrashloopBackoff.
type ServiceDependants struct {
Services map[string]service `json:"services"`
Services map[string]Service `json:"services"`
Namespace string `json:"namespace"`
}

type service struct {
Dependants []dependantPods `json:"dependantPods"`
// Service struct defines the dependent pods of a service.
type Service struct {
Dependants []DependantPods `json:"dependantPods"`
}

type dependantPods struct {
// DependantPods struct captures the details needed to identify dependant pods.
type DependantPods struct {
Name string `json:"name,omitempty"`
Selector *metav1.LabelSelector `json:"selector"`
}
2 changes: 1 addition & 1 deletion pkg/scaler/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type prober struct {
clusterLister gardenerlisterv1alpha1.ClusterLister
deploymentsLister listerappsv1.DeploymentLister
scaleInterface scale.ScaleInterface
probeDeps *probeDependants
probeDeps *ProbeDependants
initialDelay time.Duration
initialDelayTimer *time.Timer
successThreshold int32
Expand Down
4 changes: 2 additions & 2 deletions pkg/scaler/prober_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ var _ = Describe("prober", func() {
p := &prober{
namespace: ns,
secretLister: listerv1.NewSecretLister(indexer),
probeDeps: &probeDependants{
Probe: &probeConfig{
probeDeps: &ProbeDependants{
Probe: &ProbeConfig{
TimeoutSeconds: &timeout,
},
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/scaler/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (c *Controller) processNamespace(key string) error {
for i := range c.probeDependantsList.Probes {
probeDeps := &c.probeDependantsList.Probes[i]

go func(ns string, pd *probeDependants) {
go func(ns string, pd *ProbeDependants) {
p := &prober{
namespace: ns,
mapper: c.mapper,
Expand Down Expand Up @@ -286,7 +286,7 @@ func (c *Controller) processNamespace(key string) error {
return nil
}

func (c *Controller) getKey(ns string, probeDeps *probeDependants) string {
func (c *Controller) getKey(ns string, probeDeps *ProbeDependants) string {
return ns + "/" + probeDeps.Name
}

Expand Down Expand Up @@ -337,7 +337,7 @@ func (c *Controller) deleteProber(key string) {
delete(c.probers, key)
}

func (c *Controller) newContext(ns string, probeDeps *probeDependants) (context.Context, context.CancelFunc) {
func (c *Controller) newContext(ns string, probeDeps *ProbeDependants) (context.Context, context.CancelFunc) {
key := c.getKey(ns, probeDeps)

ctx, cancelFn := context.WithCancel(context.Background())
Expand Down
22 changes: 13 additions & 9 deletions pkg/scaler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,35 @@ type Controller struct {
// corresponding dependant Scales are scaled down to `zero`. They are scaled back to their
// original scale when the external probe succeeds again.
type ProbeDependantsList struct {
Probes []probeDependants `json:"probes"`
Probes []ProbeDependants `json:"probes"`
Namespace string `json:"namespace"`
}

type probeDependants struct {
// ProbeDependants struct captures the details about a probe and its dependant scale sub-resources.
type ProbeDependants struct {
Name string `json:"name"`
Probe *probeConfig `json:"probe"`
DependantScales []*dependantScaleDetails `json:"dependantScales"`
Probe *ProbeConfig `json:"probe"`
DependantScales []*DependantScaleDetails `json:"dependantScales"`
}

type probeConfig struct {
External *probeDetails `json:"external,omitempty"`
Internal *probeDetails `json:"internal,omitempty"`
// ProbeConfig struct captures the details for probing a Kubernetes apiserver.
type ProbeConfig struct {
External *ProbeDetails `json:"external,omitempty"`
Internal *ProbeDetails `json:"internal,omitempty"`
InitialDelaySeconds *int32 `json:"initialDelaySeconds,omitempty"`
TimeoutSeconds *int32 `json:"timeoutSeconds,omitempty"`
PeriodSeconds *int32 `json:"periodSeconds,omitempty"`
SuccessThreshold *int32 `json:"successThreshold,omitempty"`
FailureThreshold *int32 `json:"failureThreshold,omitempty"`
}

type probeDetails struct {
// ProbeDetails captures the kubeconfig secret details to probe a Kubernetes apiserver.
type ProbeDetails struct {
KubeconfigSecretName string `json:"kubeconfigSecretName"`
}

type dependantScaleDetails struct {
// DependantScaleDetails has the details about the dependant scale sub-resource.
type DependantScaleDetails struct {
ScaleRef autoscaling.CrossVersionObjectReference `json:"scaleRef"`
Replicas *int32 `json:"replicas"`
}
Expand Down

0 comments on commit 2cd8f69

Please sign in to comment.