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

Add go vet to the Makefile and fix its errors #691

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ ifneq ($(strip $(GIT_BRANCH)),)
TAG:=${TAG}-${RELEASE_VER}
endif

.PHONY: print-global-variables

# Build the controller executable for use in docker image build
mcad-controller: init generate-code
mcad-controller: init generate-code vet
ifeq ($(strip $(GO_BUILD_ARGS)),)
$(info Compiling controller)
CGO_ENABLED=0 go build -o ${BIN_DIR}/mcad-controller ./cmd/kar-controllers/
Expand All @@ -45,6 +44,7 @@ else
go build $(GO_BUILD_ARGS) -o ${BIN_DIR}/mcad-controller ./cmd/kar-controllers/
endif

.PHONY: print-global-variables
print-global-variables:
$(info "---")
$(info "MAKE GLOBAL VARIABLES:")
Expand All @@ -63,6 +63,12 @@ verify: generate-code
init:
mkdir -p ${BIN_DIR}

.PHONY: vet
vet: ## Run go vet against code
# Use the -printfuncs flag to specify klog functions (Errorf, Exitf, Fatalf, Infof, Warningf)
# This ensures they are considered during the vetting process.
go vet -printfuncs=Errorf,Exitf,Fatalf,Infof,Warningf ./...

verify-tag-name: print-global-variables
# Check for invalid tag name
t=${TAG} && [ $${#t} -le 128 ] || { echo "Target name $$t has 128 or more chars"; false; }
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/quotaplugins/quotasubtree/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ type Quota struct {

// QuotaSubtreeStatus is the status for a QuotaSubtree resource
type QuotaSubtreeStatus struct {
TotalAllocation ResourceAllocation `json:"totalAllocation,omitempty protobuf:"bytes,1,opt,name=totalAllocation"`
Children []ResourceAllocation `json:"children,omitempty protobuf:"bytes,2,opt,name=children"`
TotalAllocation ResourceAllocation `json:"totalAllocation,omitempty" protobuf:"bytes,1,opt,name=totalAllocation"`
Children []ResourceAllocation `json:"children,omitempty" protobuf:"bytes,2,opt,name=children"`
}

// ResourceAllocation is the spec for the child status
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/metrics/adapter/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type clusterMetricsProvider struct {
var _ provider.ExternalMetricsProvider = (*clusterMetricsProvider)(nil)

// NewFakeProvider returns an instance of clusterMetricsProvider
func NewFakeProvider(client dynamic.Interface, mapper apimeta.RESTMapper, clusterStateCache clusterstatecache.Cache) (provider.ExternalMetricsProvider) {
func NewFakeProvider(client dynamic.Interface, mapper apimeta.RESTMapper, clusterStateCache clusterstatecache.Cache) provider.ExternalMetricsProvider {
klog.V(10).Infof("[NewFakeProvider] Entered NewFakeProvider()")
provider := &clusterMetricsProvider{
client: client,
Expand Down Expand Up @@ -162,14 +162,14 @@ func (p *clusterMetricsProvider) GetExternalMetric(_ context.Context, namespace
} else if strings.Compare(labelVal, "cpu") == 0 {
// Set cpu Value
resources := p.cache2.GetUnallocatedResources()
klog.V(9).Infof("[GetExternalMetric] Cache resources: %f", resources)
klog.V(9).Infof("[GetExternalMetric] Cache resources: %v", resources)

klog.V(10).Infof("[GetExternalMetric] Setting cpu metric Value: %v.", resources.MilliCPU)
metricValue.Value = *resource.NewQuantity(int64(resources.MilliCPU), resource.DecimalSI)
} else if strings.Compare(labelVal, "gpu") == 0 {
// Set gpu Value
resources := p.cache2.GetUnallocatedResources()
klog.V(9).Infof("[GetExternalMetric] Cache resources: %f", resources)
klog.V(9).Infof("[GetExternalMetric] Cache resources: %v", resources)

klog.V(10).Infof("[GetExternalMetric] Setting gpu metric Value: %v.", resources.GPU)
metricValue.Value = *resource.NewQuantity(resources.GPU, resource.DecimalSI)
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/queuejob/queuejob_controller_ex.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,14 +1167,14 @@ func (qjm *XController) ScheduleNext(qj *arbv1.AppWrapper) {
klog.Info("%s %s %s", quotaFits, preemptAWs, msg)

if quotaFits {
klog.Infof("[ScheduleNext] [Agent mode] quota evaluation successful for app wrapper '%s/%s' activeQ=%t Unsched=%t &qj=%p Version=%s Status=%+v",
klog.Infof("[ScheduleNext] [Agent mode] quota evaluation successful for app wrapper '%s/%s' duration=%v activeQ=%t Unsched=%t &qj=%p Version=%s Status=%+v",
qj.Namespace, qj.Name, time.Now().Sub(HOLStartTime), qjm.qjqueue.IfExistActiveQ(qj), qjm.qjqueue.IfExistUnschedulableQ(qj), qj, qj.ResourceVersion, qj.Status)
// Set any jobs that are marked for preemption
qjm.preemptAWJobs(ctx, preemptAWs)
} else { // Not enough free quota to dispatch appwrapper
dispatchFailedMessage = "Insufficient quota and/or resources to dispatch AppWrapper."
dispatchFailedReason = "quota limit exceeded"
klog.Infof("[ScheduleNext] [Agent Mode] Blocking dispatch for app wrapper '%s/%s' due to quota limits, activeQ=%t Unsched=%t &qj=%p Version=%s Status=%+v msg=%s",
klog.Infof("[ScheduleNext] [Agent Mode] Blocking dispatch for app wrapper '%s/%s' duration=%v due to quota limits, activeQ=%t Unsched=%t &qj=%p Version=%s Status=%+v msg=%s",
qj.Namespace, qj.Name, time.Now().Sub(HOLStartTime), qjm.qjqueue.IfExistActiveQ(qj), qjm.qjqueue.IfExistUnschedulableQ(qj), qj, qj.ResourceVersion, qj.Status, msg)
// Call update etcd here to retrigger AW execution for failed quota
// TODO: quota management tests fail if this is converted into go-routine, need to inspect why?
Expand Down Expand Up @@ -2032,7 +2032,7 @@ func (cc *XController) manageQueueJob(ctx context.Context, qj *arbv1.AppWrapper,
if apierrors.IsInvalid(err00) {
klog.Warningf("[manageQueueJob] Invalid generic item sent for dispatching by app wrapper='%s/%s' err=%v", qj.Namespace, qj.Name, err00)
} else {
klog.Errorf("[manageQueueJob] Error dispatching generic item for app wrapper='%s/%s' type=%v err=%v", qj.Namespace, qj.Name, err00)
klog.Errorf("[manageQueueJob] Error dispatching generic item for app wrapper='%s/%s' err=%v", qj.Namespace, qj.Name, err00)
}
dispatchFailureMessage = fmt.Sprintf("%s/%s creation failure: %+v", qj.Namespace, qj.Name, err00)
dispatched = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (qm *QuotaManager) loadDispatchedAWs(dispatchedAWDemands map[string]*cluste
}

if len(preemptionIds) > 0 {
klog.Errorf("[loadDispatchedAWs] Loading of AppWrapper %s/%s caused invalid preemptions: %v. Quota Manager is in inconsistent state, reason:",
klog.Errorf("[loadDispatchedAWs] Loading of AppWrapper %s/%s caused invalid preemptions: %v. Quota Manager is in inconsistent state, reason: %v",
aw.Namespace, aw.Name, preemptionIds, errorMessage)
result = multierror.Append(result, fmt.Errorf("loading of AppWrapper %s/%s caused invalid preemptions: %v. Quota Manager is in inconsistent state",
aw.Namespace, aw.Name, preemptionIds))
Expand Down