Skip to content

Commit b98fa42

Browse files
authored
Merge pull request #2 from IBM/flag-build
Build flag, api, and go modules. ***Still need to test***
2 parents 53a85af + 97d13ff commit b98fa42

File tree

3,682 files changed

+1242294
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,682 files changed

+1242294
-25
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# But not these files...
22
!/.gitignore
33

4+
bin
5+
46
!*.go
57
!go.sum
68
!go.mod

Dockerfile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@ ARG CONTROLLER_GEN_VERSION=0.17.1
77
ARG CI_LINT_VERSION=1.52.0
88
ARG MOQ_VERSION=0.3.4
99

10+
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@v${CI_LINT_VERSION} && go install github.com/matryer/moq@v${MOQ_VERSION} && go install sigs.k8s.io/controller-tools/cmd/controller-gen@v${CONTROLLER_GEN_VERSION} && go install k8s.io/code-generator/cmd/client-gen@v${CLIENT_GEN_VERSION} && go install k8s.io/code-generator/cmd/lister-gen@v${LISTER_GEN_VERSION} && go install k8s.io/code-generator/cmd/informer-gen@v${INFORMER_GEN_VERSION}
11+
RUN git config --file=/.gitconfig --add safe.directory /work
12+
13+
WORKDIR /build
14+
COPY . .
15+
RUN pwd
16+
RUN ls -l
17+
18+
19+
#RUN mkdir /artifacts
20+
#RUN make PREFIX=/artifacts cmds
21+
22+
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4
23+
1024
LABEL io.k8s.display-name="IBM Power DRA Driver"
1125
LABEL name="IBM Power DRA Driver"
1226
LABEL vendor="IBM"
13-
LABEL version="1.0.0"
27+
LABEL version="0.1.0"
1428
LABEL release="N/A"
1529
LABEL summary="Automate the management and monitoring of addition of specific Power devices to a Pod."
1630
LABEL description="Automate the management and monitoring of addition of specific Power devices to a Pod."
1731

18-
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@v${CI_LINT_VERSION} && go install github.com/matryer/moq@v${MOQ_VERSION} && go install sigs.k8s.io/controller-tools/cmd/controller-gen@v${CONTROLLER_GEN_VERSION} && go install k8s.io/code-generator/cmd/client-gen@v${CLIENT_GEN_VERSION} && go install k8s.io/code-generator/cmd/lister-gen@v${LISTER_GEN_VERSION} && go install k8s.io/code-generator/cmd/informer-gen@v${INFORMER_GEN_VERSION}
19-
RUN git config --file=/.gitconfig --add safe.directory /work
20-
21-
COPY --from=build /power-dra-kubeletplugin /usr/bin/power-dra-kubeletplugin
32+
COPY test-kubeletplugin /usr/bin/power-dra-kubeletplugin

Makefile

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This project applies to ppc64le only
22
ARCH ?= ppc64le
33

4-
REGISTRY ?= quay.io/powercloud
4+
REGISTRY ?= quay.io/jcho0
55
REPOSITORY ?= power-dra-driver
66
TAG ?= v0.1.0
77

@@ -10,9 +10,19 @@ CONTAINER_RUNTIME ?= $(shell command -v podman 2> /dev/null || echo docker)
1010
########################################################################
1111
# Go Targets
1212

13-
#.PHONY: build
14-
#build: fmt vet
15-
# GOOS=linux GOARCH=$(ARCH) go build -o bin/power-dra-driver cmd/power-dra-driver/main.go
13+
build: fmt vet
14+
GOOS=linux GOARCH=$(ARCH) go build -o bin/power-dra-driver cmd/power-dra-driver/main.go
15+
16+
controller-gen: ## Download controller-gen locally if necessary.
17+
ifeq (, $(shell which controller-gen))
18+
go install sigs.k8s.io/controller-tools/cmd/[email protected]
19+
CONTROLLER_GEN=$(shell go env GOPATH)/bin/controller-gen
20+
else
21+
CONTROLLER_GEN=$(shell which controller-gen)
22+
endif
23+
24+
generate: controller-gen
25+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
1626

1727
.PHONY: fmt
1828
fmt:
@@ -27,27 +37,38 @@ clean:
2737
rm -f ./bin/power-dra-driver
2838
rm -rf vendor
2939

40+
BUILDIMAGE_TAG ?= golang$(GOLANG_VERSION)
41+
BUILDIMAGE ?= $(IMAGE_NAME)-build:$(BUILDIMAGE_TAG)
42+
43+
CMDS := $(patsubst ./cmd/%/,%,$(sort $(dir $(wildcard ./cmd/*/))))
44+
CMD_TARGETS := $(patsubst %,cmd-%, $(CMDS))
45+
46+
GOOS ?= linux
47+
GOARCH ?= ppc64le
48+
49+
CMDS := $(patsubst ./cmd/%/,%,$(sort $(dir $(wildcard ./cmd/*/))))
50+
CMD_TARGETS := $(patsubst %,cmd-%, $(CMDS))
51+
52+
binaries: cmds
53+
ifneq ($(PREFIX),)
54+
cmd-%: COMMAND_BUILD_OPTIONS = -o $(PREFIX)/$(*)
55+
endif
56+
cmds: $(CMD_TARGETS)
57+
$(CMD_TARGETS): cmd-%:
58+
CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' \
59+
CC=$(CC) CGO_ENABLED=1 GOOS=$(GOOS) GOARCH=$(GOARCH) \
60+
go build -ldflags "-s -w -X $(CLI_VERSION_PACKAGE).gitCommit=$(GIT_COMMIT) -X $(CLI_VERSION_PACKAGE).version=$(CLI_VERSION)" $(COMMAND_BUILD_OPTIONS) cmd/$(*)
61+
3062
########################################################################
3163
# Container Targets
3264

33-
.PHONY: image
34-
image: build
65+
.PHONY: image-build
66+
image-build: image-build
3567
$(CONTAINER_RUNTIME) buildx build \
3668
-t $(REGISTRY)/$(REPOSITORY):$(TAG) \
3769
--platform linux/$(ARCH) -f Dockerfile .
3870

39-
.PHONY: push
40-
push:
71+
.PHONY: image-push
72+
image-push:
4173
$(info push Container image...)
4274
$(CONTAINER_RUNTIME) push $(REGISTRY)/$(REPOSITORY):$(TAG)
43-
44-
########################################################################
45-
# Deployment Targets
46-
47-
.PHONY: dep-plugin
48-
dep-plugin:
49-
kustomize build manifests | oc apply -f -
50-
51-
.PHONY: dep-examples
52-
dep-examples:
53-
kustomize build examples | oc apply -f -
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright 2025.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
"k8s.io/apimachinery/pkg/runtime/schema"
23+
"k8s.io/apimachinery/pkg/runtime/serializer/json"
24+
)
25+
26+
const (
27+
GroupName = "gpu.powervs-openshift-ipi.cis.ibm.net"
28+
Version = "v1alpha1"
29+
GpuConfigKind = "GpuConfig"
30+
)
31+
32+
// Decoder implements a decoder for objects in this API group.
33+
var Decoder runtime.Decoder
34+
35+
func init() {
36+
// Create a new scheme and add our types to it. If at some point in the
37+
// future a new version of the configuration API becomes necessary, then
38+
// conversion functions can be generated and registered to continue
39+
// supporting older versions.
40+
scheme := runtime.NewScheme()
41+
schemeGroupVersion := schema.GroupVersion{
42+
Group: GroupName,
43+
Version: Version,
44+
}
45+
scheme.AddKnownTypes(schemeGroupVersion,
46+
&GpuConfig{},
47+
)
48+
metav1.AddToGroupVersion(scheme, schemeGroupVersion)
49+
50+
// Set up a json serializer to decode our types.
51+
Decoder = json.NewSerializerWithOptions(
52+
json.DefaultMetaFactory,
53+
scheme,
54+
scheme,
55+
json.SerializerOptions{
56+
Pretty: true, Strict: true,
57+
},
58+
)
59+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Copyright 2025.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// +k8s:deepcopy-gen=packages
18+
// +groupName=gpu.powervs-openshift-ipi.cis.ibm.net
19+
20+
package v1alpha1
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
Copyright 2025.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"fmt"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/utils/ptr"
24+
)
25+
26+
// +genclient
27+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
28+
29+
// GpuConfig holds the set of parameters for configuring a GPU.
30+
type GpuConfig struct {
31+
metav1.TypeMeta `json:",inline"`
32+
Sharing *GpuSharing `json:"sharing,omitempty"`
33+
}
34+
35+
// DefaultGpuConfig provides the default GPU configuration.
36+
func DefaultGpuConfig() *GpuConfig {
37+
return &GpuConfig{
38+
TypeMeta: metav1.TypeMeta{
39+
APIVersion: GroupName + "/" + Version,
40+
Kind: GpuConfigKind,
41+
},
42+
Sharing: &GpuSharing{
43+
Strategy: TimeSlicingStrategy,
44+
TimeSlicingConfig: &TimeSlicingConfig{
45+
Interval: ptr.To(DefaultTimeSlice),
46+
},
47+
},
48+
}
49+
}
50+
51+
// Normalize updates a GpuConfig config with implied default values based on other settings.
52+
func (c *GpuConfig) Normalize() error {
53+
if c == nil {
54+
return fmt.Errorf("config is 'nil'")
55+
}
56+
if c.Sharing == nil {
57+
c.Sharing = &GpuSharing{
58+
Strategy: TimeSlicingStrategy,
59+
}
60+
}
61+
if c.Sharing.Strategy == TimeSlicingStrategy && c.Sharing.TimeSlicingConfig == nil {
62+
c.Sharing.TimeSlicingConfig = &TimeSlicingConfig{
63+
Interval: "Default",
64+
}
65+
}
66+
if c.Sharing.Strategy == SpacePartitioningStrategy && c.Sharing.SpacePartitioningConfig == nil {
67+
c.Sharing.SpacePartitioningConfig = &SpacePartitioningConfig{
68+
PartitionCount: 1,
69+
}
70+
}
71+
return nil
72+
}
73+
74+
// Validate ensures that GpuConfig has a valid set of values.
75+
func (c *GpuConfig) Validate() error {
76+
if c.Sharing == nil {
77+
return fmt.Errorf("no sharing strategy set")
78+
}
79+
return c.Sharing.Validate()
80+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
Copyright 2025.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"fmt"
21+
)
22+
23+
// These constants represent the different Sharing strategies.
24+
const (
25+
TimeSlicingStrategy GpuSharingStrategy = "TimeSlicing"
26+
SpacePartitioningStrategy GpuSharingStrategy = "SpacePartitioning"
27+
)
28+
29+
// These constants represent the different TimeSlicing configurations.
30+
const (
31+
DefaultTimeSlice TimeSliceInterval = "Default"
32+
ShortTimeSlice TimeSliceInterval = "Short"
33+
MediumTimeSlice TimeSliceInterval = "Medium"
34+
LongTimeSlice TimeSliceInterval = "Long"
35+
)
36+
37+
// GpuSharingStrategy defines the valid Sharing strategies as a string.
38+
type GpuSharingStrategy string
39+
40+
// TimeSliceInterval defines the valid timeslice interval as a string.
41+
type TimeSliceInterval string
42+
43+
// GpuSharing holds the current sharing strategy for GPUs and its settings.
44+
// If DeviceClass and ResourceClaim set this, then the strategy from the claim
45+
// is used. If multiple configurations set this, then the last one is used.
46+
type GpuSharing struct {
47+
Strategy GpuSharingStrategy `json:"strategy"`
48+
TimeSlicingConfig *TimeSlicingConfig `json:"timeSlicingConfig,omitempty"`
49+
SpacePartitioningConfig *SpacePartitioningConfig `json:"spacePartitioningConfig,omitempty"`
50+
}
51+
52+
// TimeSlicingSettings provides the settings for the TimeSlicing strategy.
53+
type TimeSlicingConfig struct {
54+
Interval TimeSliceInterval `json:"interval,omitempty"`
55+
}
56+
57+
// SpacePartitioningConfig provides the configuring for the SpacePartitioning strategy.
58+
type SpacePartitioningConfig struct {
59+
// SliceCount indicates how many equally sized (memory and compute) slices
60+
// the GPU should be divided into. Each client that attaches will get
61+
// access to exactly one of these slices.
62+
PartitionCount int `json:"partitionCount,omitempty"`
63+
}
64+
65+
// IsTimeSlicing checks if the TimeSlicing strategy is applied.
66+
func (s *GpuSharing) IsTimeSlicing() bool {
67+
if s == nil {
68+
return false
69+
}
70+
return s.Strategy == TimeSlicingStrategy
71+
}
72+
73+
// IsSpacePartitioning checks if the SpacePartitioning strategy is applied.
74+
func (s *GpuSharing) IsSpacePartitioning() bool {
75+
if s == nil {
76+
return false
77+
}
78+
return s.Strategy == SpacePartitioningStrategy
79+
}
80+
81+
// GetTimeSlicingConfig returns the timeslicing config that applies to the given strategy.
82+
func (s *GpuSharing) GetTimeSlicingConfig() (*TimeSlicingConfig, error) {
83+
if s == nil {
84+
return nil, fmt.Errorf("no sharing set to get config from")
85+
}
86+
if s.Strategy != TimeSlicingStrategy {
87+
return nil, fmt.Errorf("strategy is not set to '%v'", TimeSlicingStrategy)
88+
}
89+
if s.SpacePartitioningConfig != nil {
90+
return nil, fmt.Errorf("cannot use SpacePartitioningConfig with the '%v' strategy", TimeSlicingStrategy)
91+
}
92+
return s.TimeSlicingConfig, nil
93+
}
94+
95+
// GetSpacePartitioningConfig returns the SpacePartitioning config that applies to the given strategy.
96+
func (s *GpuSharing) GetSpacePartitioningConfig() (*SpacePartitioningConfig, error) {
97+
if s == nil {
98+
return nil, fmt.Errorf("no sharing set to get config from")
99+
}
100+
if s.Strategy != SpacePartitioningStrategy {
101+
return nil, fmt.Errorf("strategy is not set to '%v'", SpacePartitioningStrategy)
102+
}
103+
if s.TimeSlicingConfig != nil {
104+
return nil, fmt.Errorf("cannot use TimeSlicingConfig with the '%v' strategy", SpacePartitioningStrategy)
105+
}
106+
return s.SpacePartitioningConfig, nil
107+
}

0 commit comments

Comments
 (0)