Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,16 @@ $(call build-image,ocp-cloud-credential-operator,$(IMAGE_REGISTRY)/ocp/4.5:cloud
$(call add-crd-gen,cloudcredential-manifests,./pkg/apis/cloudcredential/v1,./manifests,./manifests)
$(call add-crd-gen,cloudcredential-bindata,./pkg/apis/cloudcredential/v1,./bindata/bootstrap,./bindata/bootstrap)

update: update-codegen

update-codegen: update-codegen-crds
./hack/update-codegen.sh
.PHONY: update-codegen

verify: verify-codegen

verify-codegen: verify-codegen-crds
./hack/verify-codegen.sh
.PHONY: verify-codegen

clean:
Expand All @@ -102,4 +108,4 @@ vet: verify-govet
.PHONY: vet

build-no-gen: build
.PHONY: build-no-gen
.PHONY: build-no-gen
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ require (
k8s.io/api v0.18.3
k8s.io/apimachinery v0.18.3
k8s.io/client-go v0.18.3
k8s.io/code-generator v0.18.3
sigs.k8s.io/controller-runtime v0.6.0
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down Expand Up @@ -759,11 +760,13 @@ k8s.io/client-go v0.18.2/go.mod h1:Xcm5wVGXX9HAA2JJ2sSBUn3tCJ+4SVlCbl2MNNv+CIU=
k8s.io/client-go v0.18.3 h1:QaJzz92tsN67oorwzmoB0a9r9ZVHuD5ryjbCKP0U22k=
k8s.io/client-go v0.18.3/go.mod h1:4a/dpQEvzAhT1BbuWW09qvIaGw6Gbu1gZYiQZIi1DMw=
k8s.io/code-generator v0.18.2/go.mod h1:+UHX5rSbxmR8kzS+FAv7um6dtYrZokQvjHpDSYRVkTc=
k8s.io/code-generator v0.18.3 h1:5H57pYEbkMMXCLKD16YQH3yDPAbVLweUsB1M3m70D1c=
k8s.io/code-generator v0.18.3/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c=
k8s.io/component-base v0.18.2/go.mod h1:kqLlMuhJNHQ9lz8Z7V5bxUUtjFZnrypArGl58gmDfUM=
k8s.io/component-base v0.18.3 h1:QXq+P4lgi4LCIREya1RDr5gTcBaVFhxEcALir3QCSDA=
k8s.io/component-base v0.18.3/go.mod h1:bp5GzGR0aGkYEfTj+eTY0AN/vXTgkJdQXjNTTVUaa3k=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20200114144118-36b2048a9120 h1:RPscN6KhmG54S33L+lr3GS+oD1jmchIU0ll519K6FA4=
k8s.io/gengo v0.0.0-20200114144118-36b2048a9120/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
Expand Down
Empty file added hack/boilerplate.go.txt
Empty file.
46 changes: 46 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash -e

set -x

# set the passed in directory as a usable GOPATH
# that deepcopy-gen can operate in
ensure-temp-gopath() {
fake_gopath=$1

# set up symlink pointing to our repo root
fake_repopath=$fake_gopath/src/github.com/openshift/cloud-credential-operator
mkdir -p "$(dirname "${fake_repopath}")"
ln -s "$REPO_FULL_PATH" "${fake_repopath}"
}

SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
REPO_FULL_PATH=$(realpath ${SCRIPT_ROOT})
cd ${REPO_FULL_PATH}

CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../../../k8s.io/code-generator)}

verify="${VERIFY:-}"

valid_gopath=$(realpath $REPO_FULL_PATH/../../../..)
if [[ "$(realpath ${valid_gopath}/src/github.com/openshift/cloud-credential-operator)" == "${REPO_FULL_PATH}" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason you don't just always do the fake go path? It seems to me that there's less chance to have issues with other things in the real gopath if you do have one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was an optimization suggested by @staebler so that we wouldn't have to wait for the various pieces to be downloaded to the GOPATH if your usable GOPATH already had them in there. Works out that the TMP_DIR holds around 174MB of data on disk.

I'll un-WIP and squash some things up and reduce the verbosity of the deepcopy generation in a moment.

temp_gopath=${valid_gopath}
else
TMP_DIR=$(mktemp -d -t cloud-credential-operator-codegen.XXXX)
function finish {
chmod -R +w ${TMP_DIR}
# ok b/c we will symlink to the original repo
rm -r ${TMP_DIR}
}
trap finish EXIT

ensure-temp-gopath ${TMP_DIR}

temp_gopath=${TMP_DIR}
fi

GOPATH="${temp_gopath}" GOFLAGS="" bash ${CODEGEN_PKG}/generate-groups.sh "deepcopy" \
github.com/openshift/cloud-credential-operator/pkg/client \
github.com/openshift/cloud-credential-operator/pkg/apis \
"cloudcredential:v1" \
--go-header-file ${REPO_FULL_PATH}/hack/boilerplate.go.txt \
${verify}
4 changes: 4 additions & 0 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
VERIFY=--verify-only ${SCRIPT_ROOT}/hack/update-codegen.sh
79 changes: 79 additions & 0 deletions pkg/apis/cloudcredential/v1/aws_manual.deepcopy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package v1

import (
"k8s.io/apimachinery/pkg/runtime"
)

// DeepCopyInto will perform a DeepCopy into the provided AWSProviderSpec
func (in *AWSProviderSpec) DeepCopyInto(out *AWSProviderSpec) {
*out = *in
out.TypeMeta = in.TypeMeta
if in.StatementEntries != nil {
in, out := &in.StatementEntries, &out.StatementEntries
*out = make([]StatementEntry, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}

// DeepCopy will DeepCopy and return a pointer to a
// new AWSProviderSpec
func (in *AWSProviderSpec) DeepCopy() *AWSProviderSpec {
if in == nil {
return nil
}
out := new(AWSProviderSpec)
in.DeepCopyInto(out)
return out
}

// DeepCopyObject will return a DeepCopied AWSProviderSpec
// as a runtime.Object
func (in *AWSProviderSpec) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}

func deepCopyIAMPolicyCondition(ipc IAMPolicyCondition) IAMPolicyCondition {
cp := make(IAMPolicyCondition)
for key, val := range ipc {
if val != nil {
cp[key] = make(IAMPolicyConditionKeyValue)
for subKey, subVal := range val {
cp[key][subKey] = subVal
}
}
}

return cp
}

// DeepCopyInto will perform a DeepCopy into the provided StatementEntry
func (in *StatementEntry) DeepCopyInto(out *StatementEntry) {
*out = *in
if in.Action != nil {
in, out := &in.Action, &out.Action
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.PolicyCondition != nil {
out.PolicyCondition = deepCopyIAMPolicyCondition(in.PolicyCondition)
}

return
}

// DeepCopy will DeepCopy and return a pointer to a
// new StatementEntry
func (in *StatementEntry) DeepCopy() *StatementEntry {
if in == nil {
return nil
}
out := new(StatementEntry)
in.DeepCopyInto(out)
return out
}
77 changes: 77 additions & 0 deletions pkg/apis/cloudcredential/v1/aws_manual.deepcopy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package v1

import (
"testing"

"k8s.io/apimachinery/pkg/runtime"

"github.com/stretchr/testify/assert"
)

func TestAWSProviderSpecDeepCopy(t *testing.T) {

tests := []struct {
name string
providerSpec *AWSProviderSpec
}{
{
name: "basic provider spec",
providerSpec: &AWSProviderSpec{
StatementEntries: []StatementEntry{
{
Effect: "Allow",
Action: []string{
"iam:Action1",
"iam:Action2",
},
Resource: "*",
},
},
},
},
{
name: "with conditions",
providerSpec: &AWSProviderSpec{
StatementEntries: []StatementEntry{
{
Effect: "Allow",
Action: []string{
"iam:Action1",
"iam:Action2",
},
Resource: "*",
PolicyCondition: IAMPolicyCondition{
"StringEquals": IAMPolicyConditionKeyValue{
"aws:userid": "testuser",
},
"StringNotEquals": IAMPolicyConditionKeyValue{
"aws:SourceVpc": "vpc-12345",
},
},
},
},
},
},
{
name: "nil provider spec",
providerSpec: nil,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
dCopy := test.providerSpec.DeepCopy()
assert.Equal(t, test.providerSpec, dCopy, "expected the DeepCopy() results to be deeply equal")

if test.providerSpec != nil {
newAWSProviderSpec := &AWSProviderSpec{}
test.providerSpec.DeepCopyInto(newAWSProviderSpec)
assert.Equal(t, test.providerSpec, newAWSProviderSpec, "expected the DeepCopyInto() results to be deeply equal")

dCopyObject := test.providerSpec.DeepCopyObject()
testProviderSpecObject := runtime.Object(test.providerSpec)
assert.Equal(t, testProviderSpecObject, dCopyObject, "expected the DeepCopyObject() results to be equal")
}
})
}
}
7 changes: 5 additions & 2 deletions pkg/apis/cloudcredential/v1/aws_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import (
// TODO: these types should eventually be broken out, along with the actuator, to a separate repo.

// AWSProviderSpec contains the required information to create a user policy in AWS.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:deepcopy-gen=false
type AWSProviderSpec struct {
metav1.TypeMeta `json:",inline"`
// StatementEntries contains a list of policy statements that should be associated with this credentials access key.
StatementEntries []StatementEntry `json:"statementEntries"`
}

// StatementEntry models an AWS policy statement entry.
// +k8s:deepcopy-gen=false
type StatementEntry struct {
// Effect indicates if this policy statement is to Allow or Deny.
Effect string `json:"effect"`
Expand All @@ -42,7 +43,7 @@ type StatementEntry struct {
PolicyCondition IAMPolicyCondition `json:"policyCondition,omitempty"`
}

// AWSStatus containes the status of the credentials request in AWS.
// AWSProviderStatus containes the status of the credentials request in AWS.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type AWSProviderStatus struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -53,7 +54,9 @@ type AWSProviderStatus struct {
}

// IAMPolicyCondition - map of condition types, with associated key - value mapping
// +k8s:deepcopy-gen=false
type IAMPolicyCondition map[string]IAMPolicyConditionKeyValue

// IAMPolicyConditionKeyValue - mapping of values for the chosen type
// +k8s:deepcopy-gen=false
type IAMPolicyConditionKeyValue map[string]interface{}
70 changes: 1 addition & 69 deletions pkg/apis/cloudcredential/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading