Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nmaas Janitor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nmaas
nmaas Janitor
Commits
ca460f08
Commit
ca460f08
authored
5 years ago
by
Lukasz Lopatowski
Browse files
Options
Downloads
Patches
Plain Diff
Fixed StatefulSet handling
parent
6e2a742b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/service/v1/config-service.go
+16
-12
16 additions, 12 deletions
pkg/service/v1/config-service.go
pkg/service/v1/config-service_test.go
+11
-11
11 additions, 11 deletions
pkg/service/v1/config-service_test.go
with
27 additions
and
23 deletions
pkg/service/v1/config-service.go
+
16
−
12
View file @
ca460f08
...
@@ -222,7 +222,7 @@ func (s *configServiceServer) DeleteIfExists(ctx context.Context, req *v1.Instan
...
@@ -222,7 +222,7 @@ func (s *configServiceServer) DeleteIfExists(ctx context.Context, req *v1.Instan
//check if configmap exist
//check if configmap exist
_
,
err
=
s
.
kubeAPI
.
CoreV1
()
.
ConfigMaps
(
depl
.
Namespace
)
.
Get
(
depl
.
Uid
,
metav1
.
GetOptions
{})
_
,
err
=
s
.
kubeAPI
.
CoreV1
()
.
ConfigMaps
(
depl
.
Namespace
)
.
Get
(
depl
.
Uid
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
return
prepareResponse
(
v1
.
Status_OK
,
"ConfigMap not exists or is unavailable"
),
nil
return
prepareResponse
(
v1
.
Status_OK
,
"ConfigMap not exists or is unavailable"
),
nil
}
}
//delete configmap
//delete configmap
...
@@ -414,25 +414,29 @@ func (s *readinessServiceServer) CheckIfReady(ctx context.Context, req *v1.Insta
...
@@ -414,25 +414,29 @@ func (s *readinessServiceServer) CheckIfReady(ctx context.Context, req *v1.Insta
return
prepareResponse
(
v1
.
Status_FAILED
,
namespaceNotFound
),
err
return
prepareResponse
(
v1
.
Status_FAILED
,
namespaceNotFound
),
err
}
}
//
looking for deployment and checking its status
log
.
Print
(
"
looking for deployment and checking its status
"
)
dep
,
err
:=
s
.
kubeAPI
.
ExtensionsV1beta1
()
.
Deployments
(
depl
.
Namespace
)
.
Get
(
depl
.
Uid
,
metav1
.
GetOptions
{})
dep
,
err
:=
s
.
kubeAPI
.
ExtensionsV1beta1
()
.
Deployments
(
depl
.
Namespace
)
.
Get
(
depl
.
Uid
,
metav1
.
GetOptions
{})
if
err
==
nil
{
if
err
!=
nil
{
if
*
dep
.
Spec
.
Replicas
==
dep
.
Status
.
ReadyReplicas
{
log
.
Print
(
"deployment not found, looking for statefulset and checking its status"
)
return
prepareResponse
(
v1
.
Status_OK
,
"Deployment is ready"
),
nil
}
return
prepareResponse
(
v1
.
Status_PENDING
,
"Waiting for deployment"
),
err
}
else
{
//deployment not found, looking for statefulset and checking its status
sts
,
err2
:=
s
.
kubeAPI
.
AppsV1
()
.
StatefulSets
(
depl
.
Namespace
)
.
Get
(
depl
.
Uid
,
metav1
.
GetOptions
{})
sts
,
err2
:=
s
.
kubeAPI
.
AppsV1
()
.
StatefulSets
(
depl
.
Namespace
)
.
Get
(
depl
.
Uid
,
metav1
.
GetOptions
{})
if
err2
==
nil
{
if
err2
!=
nil
{
log
.
Print
(
"statefulset not found as well"
)
return
prepareResponse
(
v1
.
Status_FAILED
,
"Neither Deployment nor StatefulSet found!"
),
err2
}
else
{
log
.
Print
(
"statefulset found, verifying status"
)
if
*
sts
.
Spec
.
Replicas
==
sts
.
Status
.
ReadyReplicas
{
if
*
sts
.
Spec
.
Replicas
==
sts
.
Status
.
ReadyReplicas
{
return
prepareResponse
(
v1
.
Status_OK
,
"StatefulSet is ready"
),
nil
return
prepareResponse
(
v1
.
Status_OK
,
"StatefulSet is ready"
),
nil
}
}
return
prepareResponse
(
v1
.
Status_PENDING
,
"Waiting for deployment"
),
err
return
prepareResponse
(
v1
.
Status_PENDING
,
"Waiting for statefulset"
),
nil
}
}
else
{
log
.
Print
(
"deployment found, verifying status"
)
if
*
dep
.
Spec
.
Replicas
==
dep
.
Status
.
ReadyReplicas
{
return
prepareResponse
(
v1
.
Status_OK
,
"Deployment is ready"
),
nil
}
}
return
prepareResponse
(
v1
.
Status_PENDING
,
"Waiting for deployment"
),
nil
}
}
return
prepareResponse
(
v1
.
Status_FAILED
,
"Neither Deployment nor StatefulSet found!"
),
err
}
}
func
(
s
*
informationServiceServer
)
RetrieveServiceIp
(
ctx
context
.
Context
,
req
*
v1
.
InstanceRequest
)
(
*
v1
.
InfoServiceResponse
,
error
)
{
func
(
s
*
informationServiceServer
)
RetrieveServiceIp
(
ctx
context
.
Context
,
req
*
v1
.
InstanceRequest
)
(
*
v1
.
InfoServiceResponse
,
error
)
{
...
...
This diff is collapsed.
Click to expand it.
pkg/service/v1/config-service_test.go
+
11
−
11
View file @
ca460f08
...
@@ -114,17 +114,17 @@ func TestReadinessServiceServer_CheckIfReadyWithStatefulSet(t *testing.T) {
...
@@ -114,17 +114,17 @@ func TestReadinessServiceServer_CheckIfReadyWithStatefulSet(t *testing.T) {
}
}
//create mock statefulset that is fully deployed
//create mock statefulset that is fully deployed
sts
:=
appsv1
.
StatefulSet
{}
sts
:=
appsv1
.
StatefulSet
{}
sts
.
Name
=
"test-uid"
sts
.
Name
=
"test-uid"
q
:=
int32
(
5
)
q
:=
int32
(
5
)
sts
.
Spec
.
Replicas
=
&
q
sts
.
Spec
.
Replicas
=
&
q
sts
.
Status
.
ReadyReplicas
=
q
sts
.
Status
.
ReadyReplicas
=
q
_
,
_
=
client
.
AppsV1
()
.
StatefulSets
(
"test-namespace"
)
.
Create
(
&
sts
)
_
,
_
=
client
.
AppsV1
()
.
StatefulSets
(
"test-namespace"
)
.
Create
(
&
sts
)
res
,
err
=
server
.
CheckIfReady
(
context
.
Background
(),
&
req
)
res
,
err
=
server
.
CheckIfReady
(
context
.
Background
(),
&
req
)
if
err
!=
nil
||
res
.
Status
!=
v1
.
Status_OK
{
if
err
!=
nil
||
res
.
Status
!=
v1
.
Status_OK
{
t
.
Fail
()
t
.
Fail
()
}
}
}
}
func
TestInformationServiceServer_RetrieveServiceIp
(
t
*
testing
.
T
)
{
func
TestInformationServiceServer_RetrieveServiceIp
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment