Skip to content

Commit e12b3d6

Browse files
committed
add comments
Signed-off-by: idohu <[email protected]>
1 parent cf6d121 commit e12b3d6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

servicehandler/servicediscovery.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ func (sra *ServiceAuthentication) initialPorts(ports []v1.ServicePort) {
9393

9494
func (sra *ServiceAuthentication) Discover(ctx context.Context, scansWg *sync.WaitGroup, antsPool *ants.Pool, client dynamic.NamespaceableResourceInterface) {
9595

96+
// get all ports , each port equal different address
9697
for _, pr := range sra.spec.ports {
9798
if slices.Contains(protocolFilter, string(pr.protocol)) {
9899
continue
99100
}
100101

102+
//use DNS name to scan - this is the most reliable way to scan
101103
srvDnsName := sra.metadata.name + "." + sra.metadata.namespace
102104

103105
scansWg.Add(1)
@@ -113,8 +115,8 @@ func (sra *ServiceAuthentication) Discover(ctx context.Context, scansWg *sync.Wa
113115
logger.L().Ctx(ctx).Error(structuredErr.Error())
114116
return
115117
}
116-
_, deleteErr := client.Namespace(sra.metadata.namespace).Apply(context.TODO(), sra.metadata.name, serviceObj, metav1.ApplyOptions{FieldManager: FieldManager})
117118

119+
_, deleteErr := client.Namespace(sra.metadata.namespace).Apply(context.TODO(), sra.metadata.name, serviceObj, metav1.ApplyOptions{FieldManager: FieldManager})
118120
if deleteErr != nil {
119121
logger.L().Ctx(ctx).Error(deleteErr.Error())
120122
}
@@ -128,11 +130,13 @@ func (port *Port) Scan(ctx context.Context, ip string) {
128130
port.authenticated = result.IsAuthenticated
129131

130132
if result.ApplicationLayer == "" {
133+
// if we can't get the application layer, then we change to Unknown
131134
port.applicationLayer = "Unknown"
132135
port.authenticated = true
133136
}
134137

135138
if err != nil {
139+
//if we have an error, we log it and set all layers to Unknown
136140
logger.L().Ctx(ctx).Error(err.Error())
137141
result.ApplicationLayer = "Unknown"
138142
result.PresentationLayer = "Unknown"
@@ -142,6 +146,8 @@ func (port *Port) Scan(ctx context.Context, ip string) {
142146
}
143147

144148
func (csl currentServiceList) deleteServices(ctx context.Context, client dynamic.NamespaceableResourceInterface) error {
149+
// get all services from the current cycle and compare them with the current CRDs
150+
145151
authServices, err := client.List(context.TODO(), metav1.ListOptions{})
146152
if err != nil {
147153
return err

0 commit comments

Comments
 (0)