Skip to content

Commit

Permalink
enable gomnd
Browse files Browse the repository at this point in the history
Signed-off-by: Ziming Zhang <zziming@vmware.com>
  • Loading branch information
bitsf committed Mar 2, 2021
1 parent 9b54327 commit c9a15e5
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 23 deletions.
2 changes: 1 addition & 1 deletion controllers/goharbor/configuration/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (r *Reconciler) Reconcile(req ctrl.Request) (res ctrl.Result, err error) {
return ctrl.Result{}, fmt.Errorf("get harbor cluster cr error: %w", err)
}

log.V(5).Info("Get configmap and harbor cluster cr successfully", "configmap", cm, "harborcluster", cluster)
log.Info("Get configmap and harbor cluster cr successfully", "configmap", cm, "harborcluster", cluster)

defer func() {
log.Info("Reconcile end", "result", res, "error", err, "updateStatusErr", r.UpdateStatus(ctx, err, cluster))
Expand Down
9 changes: 7 additions & 2 deletions controllers/goharbor/harborcluster/harborcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
)

const (
DefaultWaitCycleTime = 10
ErrorWaitCycle = 5
)

var (
defaultWaitCycle = ctrl.Result{RequeueAfter: 10 * time.Second}
errorWaitCycle = ctrl.Result{RequeueAfter: 5 * time.Second}
defaultWaitCycle = ctrl.Result{RequeueAfter: DefaultWaitCycleTime * time.Second}
errorWaitCycle = ctrl.Result{RequeueAfter: ErrorWaitCycle * time.Second}
)

// Reconcile logic of the HarborCluster.
Expand Down
5 changes: 4 additions & 1 deletion controllers/goharbor/harborcluster/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

const(
TotalDependencyNum = 4
)
// status is designed to track the status and conditions of the deploying Harbor cluster.
type status struct {
client.Client
Expand Down Expand Up @@ -198,7 +201,7 @@ func (s *status) overallStatus() goharborv1.ClusterStatus {
}

// Totally ready
if ready == 4 {
if ready >= TotalDependencyNum {
return goharborv1.StatusHealthy
}

Expand Down
17 changes: 12 additions & 5 deletions pkg/cluster/controllers/cache/redis_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,23 @@ func (c *RedisConnect) NewRedisClient() *rediscli.Client {
func BuildRedisPool(redisSentinelIP []string, redisSentinelPort, redisSentinelPassword, redisGroupName string, redisIndex int) *rediscli.Client {
sentinelsInfo := GenHostInfo(redisSentinelIP, redisSentinelPort)

const (
PoolSize = 100
DialTimeout = 10
ReadTimeout = 30
WriteTimeout = 30
PoolTimeout = 30
)
options := &rediscli.FailoverOptions{
MasterName: redisGroupName,
SentinelAddrs: sentinelsInfo,
Password: redisSentinelPassword,
DB: redisIndex,
PoolSize: 100,
DialTimeout: 10 * time.Second,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
PoolTimeout: 30 * time.Second,
PoolSize: PoolSize,
DialTimeout: DialTimeout * time.Second,
ReadTimeout: ReadTimeout * time.Second,
WriteTimeout: WriteTimeout * time.Second,
PoolTimeout: PoolTimeout * time.Second,
IdleTimeout: time.Millisecond,
IdleCheckFrequency: time.Millisecond,
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cluster/controllers/cache/resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ func (rm *redisResourceManager) GetSecretName() string {
// GetSecret gets redis secret.
func (rm *redisResourceManager) GetSecret() *corev1.Secret {
name := rm.GetSecretName()
passStr := common.RandomString(8, "a")
const SecretLen = 8
passStr := common.RandomString(SecretLen, "a")

return &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/controllers/database/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ func (p *PostgreSQLController) GetPosgresMaxConnections() string {
if err != nil {
if !config.IsNotFound(err, ConfigMaxConnectionsKey) {
// Just logged
p.Log.V(5).Error(err, "failed to get database max connections")
p.Log.Error(err, "failed to get database max connections")
}

maxConnections = DefaultDatabaseMaxConnections
}

if _, err := strconv.ParseInt(maxConnections, 10, 64); err != nil {
p.Log.V(5).Error(err, "%s is not a valid number for postgres max connections", maxConnections)
p.Log.Error(err, "%s is not a valid number for postgres max connections", maxConnections)

maxConnections = DefaultDatabaseMaxConnections
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/cluster/controllers/storage/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const (

DefaultCredsSecret = "creds"
DefaultPrefix = "minio-"

DefaultZone = "zone-harbor"
DefaultRegion = "us-east-1"
DefaultBucket = "harbor"
DefaultZone = "zone-harbor"
DefaultRegion = "us-east-1"
DefaultBucket = "harbor"
DefaultServicePort = 9000
)

type MinIOController struct {
Expand Down
15 changes: 9 additions & 6 deletions pkg/cluster/controllers/storage/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ func (m *MinIOController) generateMinIOCR(ctx context.Context, harborcluster *go
return nil, err
}

const LivenessDelay = 120
const LivenessPeriod = 60
return &minio.Tenant{
TypeMeta: metav1.TypeMeta{
Kind: minio.MinIOCRDResourceKind,
Expand Down Expand Up @@ -301,8 +303,8 @@ func (m *MinIOController) generateMinIOCR(ctx context.Context, harborcluster *go
},
},
Liveness: &minio.Liveness{
InitialDelaySeconds: 120,
PeriodSeconds: 60,
InitialDelaySeconds: LivenessDelay,
PeriodSeconds: LivenessPeriod,
},
},
}, nil
Expand All @@ -313,7 +315,7 @@ func (m *MinIOController) getServiceName() string {
}

func (m *MinIOController) getServicePort() int32 {
return 9000
return DefaultServicePort
}

func (m *MinIOController) getResourceRequirements() *corev1.ResourceRequirements {
Expand Down Expand Up @@ -386,7 +388,7 @@ func (m *MinIOController) generateService() *corev1.Service {
{
Name: "minio",
Port: m.getServicePort(),
TargetPort: intstr.FromInt(9000),
TargetPort: intstr.FromInt(DefaultServicePort),
Protocol: corev1.ProtocolTCP,
},
},
Expand All @@ -395,8 +397,9 @@ func (m *MinIOController) generateService() *corev1.Service {
}

func (m *MinIOController) generateCredsSecret() *corev1.Secret {
credsAccesskey := common.RandomString(8, "a")
credsSecretkey := common.RandomString(8, "a")
const SecretLen = 8
credsAccesskey := common.RandomString(SecretLen, "a")
credsSecretkey := common.RandomString(SecretLen, "a")

return &corev1.Secret{
TypeMeta: metav1.TypeMeta{
Expand Down
2 changes: 1 addition & 1 deletion pkg/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func UpdateCondition(ctx context.Context, conditions []interface{}, conditionTyp
case 0:
case 1:
reason = reasons[0]
case 2:
case 2: // nolint:gomnd
reason = reasons[0]
message = reasons[1]
default:
Expand Down

0 comments on commit c9a15e5

Please sign in to comment.