Skip to content

Commit

Permalink
Introduce DefaultReplicas in target
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaniwaki committed Mar 22, 2022
1 parent 4be5093 commit dc44311
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/lendingconfig_types.go
Expand Up @@ -66,6 +66,8 @@ type Target struct {
Kind string `json:"kind,omitempty"`
// Name is ...
Name *string `json:"name,omitempty"`
// DefaultReplicas
DefaultReplicas *int64 `json:"defaultReplicas,omitempty"`
}

// LendingConfigSpec defines the desired state of LendingConfig
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -186,6 +186,10 @@ spec:
apiVersion:
description: APIVersion is ...
type: string
defaultReplicas:
description: DefaultReplicas
format: int64
type: integer
kind:
description: Kind is ...
type: string
Expand Down
Expand Up @@ -6,6 +6,7 @@ spec:
targets:
- kind: Deployment
apiVersion: apps/v1
defaultReplicas: 1
timezone: "Asia/Tokyo"
schedule:
default:
Expand Down
2 changes: 0 additions & 2 deletions config/samples/deployment.yaml
Expand Up @@ -2,8 +2,6 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: cluster-lending-manager-nginx
annotations:
clusterlendingmanager.dtaniwaki.github.com/default-replicas: "1"
spec:
replicas: 1
selector:
Expand Down
22 changes: 16 additions & 6 deletions controllers/lendingconfig.go
Expand Up @@ -278,13 +278,23 @@ func (config *LendingConfig) ActivateTargetResources(ctx context.Context, reconc
}
}

if defaultReplicasStr, exists := annotations[annotationNameDefaultReplicas]; exists {
defaultReplicas, err := strconv.ParseInt(defaultReplicasStr, 10, 64)
if err != nil {
return errors.WithStack(err)
if lastReplicas == nil {
if defaultReplicasStr, exists := annotations[annotationNameDefaultReplicas]; exists {
defaultReplicas, err := strconv.ParseInt(defaultReplicasStr, 10, 64)
if err != nil {
return errors.WithStack(err)
}
logger.Info(fmt.Sprintf("Use per-resource default replicas=%d.", defaultReplicas))
lastReplicas = &defaultReplicas
}
}

if lastReplicas == nil {
if target.DefaultReplicas != nil {
defaultReplicas := *target.DefaultReplicas
logger.Info(fmt.Sprintf("Use target default replicas=%d.", defaultReplicas))
lastReplicas = &defaultReplicas
}
logger.Info(fmt.Sprintf("Use default replicas=%d.", defaultReplicas))
lastReplicas = &defaultReplicas
}

if lastReplicas == nil {
Expand Down

0 comments on commit dc44311

Please sign in to comment.