Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Dockerfile, update golangci file and other minor edits #7

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# SPDX-FileCopyrightText: 2021 Open Networking Foundation <[email protected]>
# SPDX-FileCopyrightText: 2024 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
Expand Down Expand Up @@ -27,13 +28,6 @@ run:
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-files:
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
Expand All @@ -49,7 +43,7 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number
formats: colored-line-number
# print lines of code with issue, default is true
print-issued-lines: true
# print linter name in the end of issue text, default is true
Expand Down Expand Up @@ -132,10 +126,14 @@ linters-settings:
# minimal confidence for issues, default is 0.8
min-confidence: 0.8
gomnd:
settings:
mnd:
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks: argument,case,condition,operation,return,assign
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks:
- argument
- case
- condition
- operation
- return
- assign
gomodguard:
allowed:
modules: # List of allowed modules
Expand All @@ -153,8 +151,6 @@ linters-settings:
# version: "< 1.1.0" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
# reason: "testing if blocked version constraint works." # Reason why the version constraint exists. (Optional)
govet:
# report about shadowed variables
check-shadowing: true
# settings per analyzer
settings:
printf: # analyzer name, run `go tool vet help` to see all analyzers
Expand Down Expand Up @@ -200,8 +196,6 @@ linters-settings:
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
gci:
local-prefixes: "bitbucket.org"
misspell:
#locale: US
ignore-words:
Expand Down Expand Up @@ -232,7 +226,6 @@ linters:
- gofmt
- govet
- errcheck
- staticcheck
- unused
- gosimple
- ineffassign
Expand All @@ -251,14 +244,14 @@ linters:
- gofumpt
- whitespace
- unconvert
# - predeclared
- predeclared
- noctx
- dogsled
# - bodyclose
- asciicheck
#- stylecheck
# - stylecheck
- unparam
# - wsl
# - wsl

#disable-all: false
fast: true
Expand Down
12 changes: 4 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

FROM golang:1.23.2-bookworm AS builder

LABEL maintainer="Aether SD-Core <[email protected]>"

WORKDIR $GOPATH/src/upfadapter
COPY . .
RUN make all

FROM alpine:3.20 AS upfadapter

LABEL description="Aether open source 5G Core Network" \
LABEL maintainer="Aether SD-Core <[email protected]>" \
description="ONF open source 5G Core Network" \
version="Stage 3"

ARG DEBUG_TOOLS
Expand All @@ -25,8 +24,5 @@ RUN if [ "$DEBUG_TOOLS" = "true" ]; then \
apk update && apk add --no-cache -U vim strace net-tools curl netcat-openbsd bind-tools; \
fi

# Set working dir
WORKDIR /aether

# Copy executable and default certs
COPY --from=builder /go/src/upfadapter/bin/* .
# Copy executable
COPY --from=builder /go/src/upfadapter/bin/* /usr/local/bin/.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func IsUpfAssociated(nodeId types.NodeID) bool {
UpfCfg.UpfListLock.RLock()
defer UpfCfg.UpfListLock.RUnlock()

logger.CfgLog.Debugf("associated upfs: [ %v]", UpfCfg.UPFs)
logger.CfgLog.Debugf("associated upfs: [%v]", UpfCfg.UPFs)

if upf := UpfCfg.UPFs[string(nodeId.NodeIdValue)]; upf != nil {
if upf.State == AssociatedSetUpSuccess {
Expand Down
10 changes: 5 additions & 5 deletions types/nodeid.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ func (n *NodeID) ResolveNodeIdToIp() net.IP {
return n.NodeIdValue
case NodeIdTypeFqdn:
if ip, err := getDnsHostIp(string(n.NodeIdValue)); err != nil {
logger.AppLog.Warnf("host [%v] not found in smf dns cache ", string(n.NodeIdValue))
logger.AppLog.Warnf("host [%v] not found in smf dns cache", string(n.NodeIdValue))
if ns, err := net.LookupHost(string(n.NodeIdValue)); err != nil {
logger.AppLog.Warnf("Host lookup failed: %+v", err)
return net.IPv4zero
} else {
logger.AppLog.Infof("host [%v] dns resolved, updating smf dns cache ", string(n.NodeIdValue))
logger.AppLog.Infof("host [%v] dns resolved, updating smf dns cache", string(n.NodeIdValue))
InsertDnsHostIp(string(n.NodeIdValue), net.ParseIP(ns[0]))
return net.ParseIP(ns[0])
}
} else {
logger.AppLog.Debugf("host [%v] found in smf dns cache ", string(n.NodeIdValue))
logger.AppLog.Debugf("host [%v] found in smf dns cache", string(n.NodeIdValue))
return ip
}
default:
Expand All @@ -82,13 +82,13 @@ func init() {

func RefreshDnsHostIpCache() {
for hostName := range dnsHostIpCache {
logger.AppLog.Debugf("refreshing DNS for host [%v] ", hostName)
logger.AppLog.Debugf("refreshing DNS for host [%v]", hostName)
if ns, err := net.LookupHost(hostName); err != nil {
logger.AppLog.Warnf("Host lookup failed: %+v", err)
deleteDnsHost(hostName)
continue
} else if !dnsHostIpCache[hostName].Equal(net.ParseIP(ns[0])) {
logger.AppLog.Infof("smf dns cache updated for host [%v]: [%v] ", hostName, net.ParseIP(ns[0]).String())
logger.AppLog.Infof("smf dns cache updated for host [%v]: [%v]", hostName, net.ParseIP(ns[0]).String())
dnsHostIpCache[hostName] = net.ParseIP(ns[0])
}
}
Expand Down
6 changes: 3 additions & 3 deletions upfadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/wmnsk/go-pfcp/message"
)

// Hnadler for SMF initiated msgs
// Handler for SMF initiated msgs
func handler(w http.ResponseWriter, req *http.Request) {
reqBody, err := io.ReadAll(req.Body)
if err != nil {
Expand All @@ -28,13 +28,13 @@ func handler(w http.ResponseWriter, req *http.Request) {
var udpPodMsg config.UdpPodPfcpMsg
err = json.Unmarshal(reqBody, &udpPodMsg)
if err != nil {
logger.AppLog.Errorf("error unmarshalling pfcp msg")
logger.AppLog.Errorln("error unmarshalling pfcp msg")
return
}

pfcpMessage, err := message.Parse(udpPodMsg.Msg.Body)
if err != nil {
logger.AppLog.Errorf("error parsing pfcp msg")
logger.AppLog.Errorln("error parsing pfcp msg")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand Down