Skip to content
GitLab
Next
Projects
Groups
Snippets
Help
Loading...
Help
What's new
6
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
GitLab Operator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
28
Issues
28
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
6
Merge Requests
6
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GitLab.org
OpenShift
GitLab Operator
Commits
39870211
Commit
39870211
authored
Sep 11, 2020
by
Edmund Ochieng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update logic to update hpa
parent
6aabfbc7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
20 deletions
+46
-20
controllers/gitlab/hpa.go
controllers/gitlab/hpa.go
+4
-0
controllers/gitlab_controller.go
controllers/gitlab_controller.go
+40
-13
controllers/gitlab_status.go
controllers/gitlab_status.go
+2
-7
No files found.
controllers/gitlab/hpa.go
View file @
39870211
...
...
@@ -17,6 +17,10 @@ func getHPALabels(labels map[string]string) map[string]string {
func
HorizontalAutoscaler
(
deployment
*
appsv1
.
Deployment
,
cr
*
gitlabv1beta1
.
GitLab
)
*
autoscalingv1
.
HorizontalPodAutoscaler
{
labels
:=
getHPALabels
(
deployment
.
ObjectMeta
.
Labels
)
if
cr
.
Spec
.
AutoScaling
==
nil
{
return
nil
}
return
&
autoscalingv1
.
HorizontalPodAutoscaler
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
deployment
.
Name
,
...
...
controllers/gitlab_controller.go
View file @
39870211
...
...
@@ -632,27 +632,54 @@ func (r *GitLabReconciler) setupAutoscaling(ctx context.Context, cr *gitlabv1bet
}
for
_
,
deploy
:=
range
deployments
.
Items
{
if
!
strings
.
Contains
(
deploy
.
Name
,
"gitlab-exporter"
)
{
hpa
:=
gitlabctl
.
HorizontalAutoscaler
(
&
deploy
,
cr
)
if
err
:=
r
.
reconcileHPA
(
ctx
,
&
deploy
,
cr
);
err
!=
nil
{
return
err
}
}
return
nil
}
func
(
r
*
GitLabReconciler
)
reconcileHPA
(
ctx
context
.
Context
,
deployment
*
appsv1
.
Deployment
,
cr
*
gitlabv1beta1
.
GitLab
)
error
{
if
strings
.
Contains
(
deployment
.
Name
,
"gitlab-exporter"
)
{
return
nil
}
hpa
:=
gitlabctl
.
HorizontalAutoscaler
(
deployment
,
cr
)
found
:=
&
autoscalingv1
.
HorizontalPodAutoscaler
{}
err
:=
r
.
Get
(
ctx
,
types
.
NamespacedName
{
Name
:
deployment
.
Name
,
Namespace
:
cr
.
Namespace
},
found
)
if
err
!=
nil
{
if
errors
.
IsNotFound
(
err
)
{
if
err
:=
controllerutil
.
SetControllerReference
(
cr
,
hpa
,
r
.
Scheme
);
err
!=
nil
{
return
err
}
found
:=
&
autoscalingv1
.
HorizontalPodAutoscaler
{}
err
:=
r
.
Get
(
ctx
,
types
.
NamespacedName
{
Name
:
hpa
.
Name
,
Namespace
:
cr
.
Namespace
},
found
)
if
err
!=
nil
{
if
errors
.
IsNotFound
(
err
)
{
return
r
.
Create
(
ctx
,
hpa
)
}
return
r
.
Create
(
ctx
,
hpa
)
}
return
err
}
return
err
}
if
!
reflect
.
DeepEqual
(
hpa
.
Spec
,
found
.
Spec
)
{
return
r
.
Patch
(
ctx
,
found
,
client
.
MergeFrom
(
hpa
))
}
if
cr
.
Spec
.
AutoScaling
==
nil
{
return
r
.
Delete
(
ctx
,
found
)
}
if
!
reflect
.
DeepEqual
(
hpa
.
Spec
,
found
.
Spec
)
{
if
*
found
.
Spec
.
MinReplicas
!=
*
hpa
.
Spec
.
MinReplicas
{
found
.
Spec
.
MinReplicas
=
hpa
.
Spec
.
MinReplicas
}
if
found
.
Spec
.
MaxReplicas
!=
hpa
.
Spec
.
MaxReplicas
{
found
.
Spec
.
MaxReplicas
=
hpa
.
Spec
.
MaxReplicas
}
if
found
.
Spec
.
TargetCPUUtilizationPercentage
!=
hpa
.
Spec
.
TargetCPUUtilizationPercentage
{
found
.
Spec
.
TargetCPUUtilizationPercentage
=
hpa
.
Spec
.
TargetCPUUtilizationPercentage
}
return
r
.
Update
(
ctx
,
found
)
}
return
nil
...
...
controllers/gitlab_status.go
View file @
39870211
...
...
@@ -23,7 +23,8 @@ var EndpointMembers []string
func
(
r
*
GitLabReconciler
)
reconcileGitlabStatus
(
cr
*
gitlabv1beta1
.
GitLab
)
error
{
// get current Gitlab resource
gitlab
,
err
:=
r
.
retrieveUpdatedGitlabResource
(
cr
)
gitlab
:=
&
gitlabv1beta1
.
GitLab
{}
err
:=
r
.
Get
(
context
.
TODO
(),
types
.
NamespacedName
{
Namespace
:
cr
.
Namespace
,
Name
:
cr
.
Name
},
gitlab
)
if
err
!=
nil
{
return
err
}
...
...
@@ -140,12 +141,6 @@ func (r *GitLabReconciler) isWebserviceDeployed(cr *gitlabv1beta1.GitLab) bool {
return
!
reflect
.
DeepEqual
(
*
webservice
,
appsv1
.
Deployment
{})
||
!
errors
.
IsNotFound
(
err
)
}
func
(
r
*
GitLabReconciler
)
retrieveUpdatedGitlabResource
(
cr
*
gitlabv1beta1
.
GitLab
)
(
*
gitlabv1beta1
.
GitLab
,
error
)
{
gitlab
:=
&
gitlabv1beta1
.
GitLab
{}
err
:=
r
.
Get
(
context
.
TODO
(),
types
.
NamespacedName
{
Namespace
:
cr
.
Namespace
,
Name
:
cr
.
Name
},
gitlab
)
return
gitlab
,
err
}
// setGitlabStatus sets status of custom resource
func
(
r
*
GitLabReconciler
)
setGitlabStatus
(
object
runtime
.
Object
)
error
{
return
r
.
Status
()
.
Update
(
context
.
TODO
(),
object
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment