Skip to content

Commit ceeac5f

Browse files
committed
Changes for working with secrets from cloud-credentials-operator
Signed-off-by: Roy Golan <[email protected]>
1 parent 289621f commit ceeac5f

File tree

13 files changed

+252
-135
lines changed

13 files changed

+252
-135
lines changed

Dockerfile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
FROM registry.svc.ci.openshift.org/openshift/release:golang-1.12 AS builder
14+
15+
ARG version
16+
ARG release
17+
18+
LABEL com.redhat.component="machine-api" \
19+
name="cluster-api-provider-ovirt" \
20+
version="$version" \
21+
release="$release" \
22+
architecture="x86_64" \
23+
summary="cluster-api-provider-ovirt" \
24+
maintainer="Roy Golan <[email protected]>"
25+
26+
WORKDIR /go/cluster-api-provider-ovirt
27+
COPY . .
28+
29+
RUN make build
30+
31+
FROM registry.access.redhat.com/ubi8/ubi-minimal
32+
33+
COPY --from=builder /go/cluster-api-provider-ovirt/bin/manager /
34+
COPY --from=builder /go/cluster-api-provider-ovirt/bin/machine-controller-manager /

Makefile

+22-8
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,34 @@ VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
1515
GOFLAGS += -mod vendor
1616
TAGS :=
1717
LDFLAGS := "-w -s -X 'main.version=${VERSION}'"
18-
REGISTRY ?= quay.io/rgolangh
18+
REGISTRY ?= quay.io/ovirt
19+
20+
VERSION?=$(shell git describe --tags --always --match "v[0-9]*" | awk -F'-' '{print substr($$1,2) }')
21+
RELEASE?=$(shell git describe --tags --always --match "v[0-9]*" | awk -F'-' '{if ($$2 != "") {print $$2 "." $$3} else {print 1}}')
22+
VERSION_RELEASE=$(VERSION)$(if $(RELEASE),-$(RELEASE))
1923

2024
.PHONY: vendor
2125
vendor:
22-
go mod tidy
23-
go mod vendor
24-
go mod verify
26+
go mod tidy
27+
go mod vendor
28+
go mod verify
2529

2630
$(GOBIN):
2731
echo "create gobin"
2832
mkdir -p $(GOBIN)
2933

3034
work: $(GOBIN)
3135

32-
build: manager
33-
34-
manager:
36+
build: export BUILDAH_LAYERS=true
37+
build:
3538
CGO_ENABLED=0 GOOS=$(GOOS) go build \
3639
-ldflags $(LDFLAGS) \
3740
-o bin/manager \
3841
cmd/manager/main.go
42+
CGO_ENABLED=0 GOOS=$(GOOS) go build \
43+
-ldflags $(LDFLAGS) \
44+
-o bin/machine-controller-manager \
45+
cmd/manager/main.go
3946

4047
test: unit functional
4148

@@ -104,7 +111,14 @@ shell:
104111
generate:
105112
go generate ./pkg/... ./cmd/...
106113

107-
images: ovirt-cluster-api-controller
114+
DOCKERFILE=Dockerfile
115+
images:
116+
podman build \
117+
-t $(REGISTRY)/cluster-api-provider-ovirt:$(VERSION_RELEASE) \
118+
--build-arg version=$(VERSION) \
119+
--build-arg release=$(RELEASE) \
120+
-f $(DOCKERFILE) \
121+
$(DIR)
108122

109123
ovirt-cluster-api-controller: manager
110124

cmd/manager/Dockerfile

-20
This file was deleted.

config/manager/manager.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ metadata:
3030
namespace: ovirt-cluster-provider-system
3131
data:
3232
OS_CLOUD: >
33-
url: https://rgolan.usersys.redhat.com:8443/ovirt-engine/api
33+
url: https://ovirt-engine-fqdn/ovirt-engine/api
3434
username: admin@internal
3535
password: 123
3636
cafile: /dev/null

docs/config.md

-41
This file was deleted.

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ require (
99
github.com/onsi/ginkgo v1.8.0
1010
github.com/onsi/gomega v1.5.0
1111
github.com/openshift/cluster-api v0.0.0-20190917100308-655e2d6ccdd5
12+
github.com/ovirt/go-ovirt v4.3.4+incompatible
13+
github.com/pkg/errors v0.8.1
1214
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 // indirect
15+
github.com/prometheus/common v0.2.0
1316
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 // indirect
1417
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
1518
gopkg.in/yaml.v2 v2.2.2

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
9494
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
9595
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
9696
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
97+
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223 h1:F9x/1yl3T2AeKLr2AMdilSD8+f9bvMnNN8VS5iDtovc=
9798
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
9899
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
99100
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -105,6 +106,8 @@ github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
105106
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
106107
github.com/openshift/cluster-api v0.0.0-20190917100308-655e2d6ccdd5 h1:r1srojcJfutWWqI++8p7j4xRX0n4e88nCBOqkIdYsa0=
107108
github.com/openshift/cluster-api v0.0.0-20190917100308-655e2d6ccdd5/go.mod h1:mNsD1dsD4T57kV4/C6zTHke/Ro166xgnyyRZqkamiEU=
109+
github.com/ovirt/go-ovirt v4.3.4+incompatible h1:jXcJpcXyNZ3mXJ1IVU3l3tMpE4JEUSNjqRiEJnVpG40=
110+
github.com/ovirt/go-ovirt v4.3.4+incompatible/go.mod h1:r33ZGjVKCPMiI6hw791/Zx8tNKk0Gn+4VFWbOfyIvZQ=
108111
github.com/pborman/uuid v0.0.0-20170612153648-e790cca94e6c h1:MUyE44mTvnI5A0xrxIxaMqoWFzPfQvtE2IWUollMDMs=
109112
github.com/pborman/uuid v0.0.0-20170612153648-e790cca94e6c/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34=
110113
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

pkg/apis/ovirtclusterproviderconfig/v1alpha1/register.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const GroupName = "ovirtclusterproviderconfig"
3333

3434
var (
3535
// SchemeGroupVersion is group version used to register these objects
36-
SchemeGroupVersion = schema.GroupVersion{Group: fmt.Sprintf("%s.k8s.io", GroupName), Version: "v1alpha1"}
36+
SchemeGroupVersion = schema.GroupVersion{Group: fmt.Sprintf("%s.k8s.io", GroupName), Version: "v1beta1"}
3737

3838
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
3939
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}

pkg/apis/ovirtclusterproviderconfig/v1alpha1/types.go

+7
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ type OvirtMachineProviderSpec struct {
3030
metav1.TypeMeta `json:",inline"`
3131
metav1.ObjectMeta `json:"metadata,omitempty"`
3232

33+
// UserDataSecret contains a local reference to a secret that contains the
34+
// UserData to apply to the instance
35+
UserDataSecret *corev1.LocalObjectReference `json:"userDataSecret,omitempty"`
36+
3337
// CredentialsSecret is a reference to the secret with oVirt credentials.
3438
CredentialsSecret *corev1.LocalObjectReference `json:"credentialsSecret,omitempty"`
3539

40+
// Id is the UUID of the VM
3641
Id string `json:"id"`
42+
43+
// Name is the VM name
3744
Name string `json:"name"`
3845
// The VM template this instance will be created from
3946
TemplateId string `json:"template_id"`
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package clients
2+
3+
import (
4+
"context"
5+
"fmt"
6+
apicorev1 "k8s.io/api/core/v1"
7+
8+
machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
9+
"k8s.io/apimachinery/pkg/api/errors"
10+
"sigs.k8s.io/controller-runtime/pkg/client"
11+
12+
"github.com/ovirt/cluster-api-provider-ovirt/pkg/apis/ovirtclusterproviderconfig/v1alpha1"
13+
)
14+
15+
func getCredentialsSecret(coreClient client.Client, machine machinev1.Machine, spec v1alpha1.OvirtMachineProviderSpec) (map[string][]byte, error) {
16+
if spec.CredentialsSecret == nil {
17+
return nil, nil
18+
}
19+
var credentialsSecret apicorev1.Secret
20+
21+
if err := coreClient.Get(context.Background(), client.ObjectKey{Namespace: machine.GetNamespace(), Name: spec.CredentialsSecret.Name}, &credentialsSecret); err != nil {
22+
if errors.IsNotFound(err) {
23+
return nil, fmt.Errorf("error getting credentials secret %q in namespace %q: %v", spec.CredentialsSecret.Name, machine.GetNamespace(), err)
24+
}
25+
}
26+
27+
return credentialsSecret.Data, nil
28+
}
29+

0 commit comments

Comments
 (0)