Skip to content

Commit

Permalink
Added healthcheck changes
Browse files Browse the repository at this point in the history
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk-pawel.strusiewicz-surmacki@external.telekom.de>
  • Loading branch information
p-strusiewiczsurmacki-mobica committed Apr 17, 2024
1 parent 375ebba commit f73e182
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ func (hc *HealthChecker) CheckReachability() error {
return nil
}

// CheckAPIServer checks if Kubernetes API Server is reachable.
func (hc *HealthChecker) CheckAPIServer(ctx context.Context) error {
pods := &corev1.PodList{}
if err := hc.client.List(ctx, pods); err != nil {
return fmt.Errorf("error listing pods: %w", err)
}
return nil
}

func (hc *HealthChecker) checkReachabilityItem(r netReachabilityItem) error {
target := r.Host + ":" + strconv.Itoa(r.Port)
conn, err := hc.toolkit.tcpDialer.Dial("tcp", target)
Expand Down
10 changes: 10 additions & 0 deletions pkg/healthcheck/healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ var _ = Describe("HealthCheck", func() {
Expect(err).To(HaveOccurred())
})
})
Context("CheckAPIServer() should", func() {
It("return no error", func() {
c := fake.NewClientBuilder().Build()
hc, err := NewHealthChecker(c, NewHealthCheckToolkit(nil, nil, nil), &NetHealthcheckConfig{})
Expect(err).ToNot(HaveOccurred())
Expect(hc).ToNot(BeNil())
err = hc.CheckAPIServer(context.TODO())
Expect(err).ToNot(HaveOccurred())
})
})
})

func fakeErrorGetByName(_ string) (netlink.Link, error) {
Expand Down

0 comments on commit f73e182

Please sign in to comment.