From 6edec2ea5fc2d9ff2df289d7bb254a7af6364dc4 Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Sat, 19 Jun 2021 00:59:13 -0700 Subject: [PATCH 01/10] feat(aws): add support for amazon mq Signed-off-by: Praveen Ghuge --- apis/aws.go | 2 + apis/mq/v1alpha1/custom_type | 0 apis/mq/v1alpha1/custom_types.go | 20 + apis/mq/v1alpha1/generator-config.yaml | 4 + apis/mq/v1alpha1/zz_broker.go | 126 ++ apis/mq/v1alpha1/zz_doc.go | 24 + apis/mq/v1alpha1/zz_enums.go | 86 ++ apis/mq/v1alpha1/zz_generated.deepcopy.go | 1066 +++++++++++++++++ apis/mq/v1alpha1/zz_generated.managed.go | 77 ++ apis/mq/v1alpha1/zz_generated.managedlist.go | 30 + apis/mq/v1alpha1/zz_groupversion_info.go | 41 + apis/mq/v1alpha1/zz_types.go | 243 ++++ .../crds/mq.aws.crossplane.io_brokers.yaml | 256 ++++ pkg/controller/aws.go | 2 + pkg/controller/mq/broker/setup.go | 31 + pkg/controller/mq/broker/zz_controller.go | 231 ++++ pkg/controller/mq/broker/zz_conversions.go | 348 ++++++ 17 files changed, 2587 insertions(+) create mode 100644 apis/mq/v1alpha1/custom_type create mode 100644 apis/mq/v1alpha1/custom_types.go create mode 100644 apis/mq/v1alpha1/generator-config.yaml create mode 100644 apis/mq/v1alpha1/zz_broker.go create mode 100644 apis/mq/v1alpha1/zz_doc.go create mode 100644 apis/mq/v1alpha1/zz_enums.go create mode 100644 apis/mq/v1alpha1/zz_generated.deepcopy.go create mode 100644 apis/mq/v1alpha1/zz_generated.managed.go create mode 100644 apis/mq/v1alpha1/zz_generated.managedlist.go create mode 100644 apis/mq/v1alpha1/zz_groupversion_info.go create mode 100644 apis/mq/v1alpha1/zz_types.go create mode 100644 package/crds/mq.aws.crossplane.io_brokers.yaml create mode 100644 pkg/controller/mq/broker/setup.go create mode 100644 pkg/controller/mq/broker/zz_controller.go create mode 100644 pkg/controller/mq/broker/zz_conversions.go diff --git a/apis/aws.go b/apis/aws.go index aac20ac01e..73abcb9b35 100644 --- a/apis/aws.go +++ b/apis/aws.go @@ -43,6 +43,7 @@ import ( kafkav1alpha1 "github.com/crossplane/provider-aws/apis/kafka/v1alpha1" kmsv1alpha1 "github.com/crossplane/provider-aws/apis/kms/v1alpha1" lambdav1alpha1 "github.com/crossplane/provider-aws/apis/lambda/v1alpha1" + mqv1alpha1 "github.com/crossplane/provider-aws/apis/mq/v1alpha1" notificationv1alpha3 "github.com/crossplane/provider-aws/apis/notification/v1alpha1" rdsv1alpha1 "github.com/crossplane/provider-aws/apis/rds/v1alpha1" redshiftv1alpha1 "github.com/crossplane/provider-aws/apis/redshift/v1alpha1" @@ -99,6 +100,7 @@ func init() { kafkav1alpha1.SchemeBuilder.AddToScheme, transferv1alpha1.SchemeBuilder.AddToScheme, gluev1alpha1.SchemeBuilder.AddToScheme, + mqv1alpha1.SchemeBuilder.AddToScheme, ) } diff --git a/apis/mq/v1alpha1/custom_type b/apis/mq/v1alpha1/custom_type new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apis/mq/v1alpha1/custom_types.go b/apis/mq/v1alpha1/custom_types.go new file mode 100644 index 0000000000..6477a6d72c --- /dev/null +++ b/apis/mq/v1alpha1/custom_types.go @@ -0,0 +1,20 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +// CustomBrokerParameters contains the additional fields for CustomBrokerParameters +type CustomBrokerParameters struct{} diff --git a/apis/mq/v1alpha1/generator-config.yaml b/apis/mq/v1alpha1/generator-config.yaml new file mode 100644 index 0000000000..a4a22158ed --- /dev/null +++ b/apis/mq/v1alpha1/generator-config.yaml @@ -0,0 +1,4 @@ +ignore: + resource_names: + - Configuration + - User \ No newline at end of file diff --git a/apis/mq/v1alpha1/zz_broker.go b/apis/mq/v1alpha1/zz_broker.go new file mode 100644 index 0000000000..f332165f58 --- /dev/null +++ b/apis/mq/v1alpha1/zz_broker.go @@ -0,0 +1,126 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package v1alpha1 + +import ( + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// BrokerParameters defines the desired state of Broker +type BrokerParameters struct { + // Region is which region the Broker will be created. + // +kubebuilder:validation:Required + Region string `json:"region"` + + AuthenticationStrategy *string `json:"authenticationStrategy,omitempty"` + + AutoMinorVersionUpgrade *bool `json:"autoMinorVersionUpgrade,omitempty"` + + BrokerName *string `json:"brokerName,omitempty"` + + Configuration *ConfigurationID `json:"configuration,omitempty"` + + CreatorRequestID *string `json:"creatorRequestID,omitempty"` + + DeploymentMode *string `json:"deploymentMode,omitempty"` + + EncryptionOptions *EncryptionOptions `json:"encryptionOptions,omitempty"` + + EngineType *string `json:"engineType,omitempty"` + + EngineVersion *string `json:"engineVersion,omitempty"` + + HostInstanceType *string `json:"hostInstanceType,omitempty"` + + LDAPServerMetadata *LDAPServerMetadataInput `json:"ldapServerMetadata,omitempty"` + + Logs *Logs `json:"logs,omitempty"` + + MaintenanceWindowStartTime *WeeklyStartTime `json:"maintenanceWindowStartTime,omitempty"` + + PubliclyAccessible *bool `json:"publiclyAccessible,omitempty"` + + SecurityGroups []*string `json:"securityGroups,omitempty"` + + StorageType *string `json:"storageType,omitempty"` + + SubnetIDs []*string `json:"subnetIDs,omitempty"` + + Tags map[string]*string `json:"tags,omitempty"` + + Users []*User `json:"users,omitempty"` + CustomBrokerParameters `json:",inline"` +} + +// BrokerSpec defines the desired state of Broker +type BrokerSpec struct { + xpv1.ResourceSpec `json:",inline"` + ForProvider BrokerParameters `json:"forProvider"` +} + +// BrokerObservation defines the observed state of Broker +type BrokerObservation struct { + BrokerARN *string `json:"brokerARN,omitempty"` + + BrokerID *string `json:"brokerID,omitempty"` +} + +// BrokerStatus defines the observed state of Broker. +type BrokerStatus struct { + xpv1.ResourceStatus `json:",inline"` + AtProvider BrokerObservation `json:"atProvider,omitempty"` +} + +// +kubebuilder:object:root=true + +// Broker is the Schema for the Brokers API +// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" +// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" +// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name" +// +kubebuilder:subresource:status +// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,aws} +type Broker struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Spec BrokerSpec `json:"spec"` + Status BrokerStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// BrokerList contains a list of Brokers +type BrokerList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Broker `json:"items"` +} + +// Repository type metadata. +var ( + BrokerKind = "Broker" + BrokerGroupKind = schema.GroupKind{Group: Group, Kind: BrokerKind}.String() + BrokerKindAPIVersion = BrokerKind + "." + GroupVersion.String() + BrokerGroupVersionKind = GroupVersion.WithKind(BrokerKind) +) + +func init() { + SchemeBuilder.Register(&Broker{}, &BrokerList{}) +} diff --git a/apis/mq/v1alpha1/zz_doc.go b/apis/mq/v1alpha1/zz_doc.go new file mode 100644 index 0000000000..ad578d60e4 --- /dev/null +++ b/apis/mq/v1alpha1/zz_doc.go @@ -0,0 +1,24 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +// +kubebuilder:object:generate=true +// Package v1alpha1 is the v1alpha1 version of the mq.aws.crossplane.io API. +// +groupName=mq.aws.crossplane.io +// +versionName=v1alpha1 + +package v1alpha1 diff --git a/apis/mq/v1alpha1/zz_enums.go b/apis/mq/v1alpha1/zz_enums.go new file mode 100644 index 0000000000..1b18841c07 --- /dev/null +++ b/apis/mq/v1alpha1/zz_enums.go @@ -0,0 +1,86 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package v1alpha1 + +type AuthenticationStrategy string + +const ( + AuthenticationStrategy_SIMPLE AuthenticationStrategy = "SIMPLE" + AuthenticationStrategy_LDAP AuthenticationStrategy = "LDAP" +) + +type BrokerState string + +const ( + BrokerState_CREATION_IN_PROGRESS BrokerState = "CREATION_IN_PROGRESS" + BrokerState_CREATION_FAILED BrokerState = "CREATION_FAILED" + BrokerState_DELETION_IN_PROGRESS BrokerState = "DELETION_IN_PROGRESS" + BrokerState_RUNNING BrokerState = "RUNNING" + BrokerState_REBOOT_IN_PROGRESS BrokerState = "REBOOT_IN_PROGRESS" +) + +type BrokerStorageType string + +const ( + BrokerStorageType_EBS BrokerStorageType = "EBS" + BrokerStorageType_EFS BrokerStorageType = "EFS" +) + +type ChangeType string + +const ( + ChangeType_CREATE ChangeType = "CREATE" + ChangeType_UPDATE ChangeType = "UPDATE" + ChangeType_DELETE ChangeType = "DELETE" +) + +type DayOfWeek string + +const ( + DayOfWeek_MONDAY DayOfWeek = "MONDAY" + DayOfWeek_TUESDAY DayOfWeek = "TUESDAY" + DayOfWeek_WEDNESDAY DayOfWeek = "WEDNESDAY" + DayOfWeek_THURSDAY DayOfWeek = "THURSDAY" + DayOfWeek_FRIDAY DayOfWeek = "FRIDAY" + DayOfWeek_SATURDAY DayOfWeek = "SATURDAY" + DayOfWeek_SUNDAY DayOfWeek = "SUNDAY" +) + +type DeploymentMode string + +const ( + DeploymentMode_SINGLE_INSTANCE DeploymentMode = "SINGLE_INSTANCE" + DeploymentMode_ACTIVE_STANDBY_MULTI_AZ DeploymentMode = "ACTIVE_STANDBY_MULTI_AZ" + DeploymentMode_CLUSTER_MULTI_AZ DeploymentMode = "CLUSTER_MULTI_AZ" +) + +type EngineType string + +const ( + EngineType_ACTIVEMQ EngineType = "ACTIVEMQ" + EngineType_RABBITMQ EngineType = "RABBITMQ" +) + +type SanitizationWarningReason string + +const ( + SanitizationWarningReason_DISALLOWED_ELEMENT_REMOVED SanitizationWarningReason = "DISALLOWED_ELEMENT_REMOVED" + SanitizationWarningReason_DISALLOWED_ATTRIBUTE_REMOVED SanitizationWarningReason = "DISALLOWED_ATTRIBUTE_REMOVED" + SanitizationWarningReason_INVALID_ATTRIBUTE_VALUE_REMOVED SanitizationWarningReason = "INVALID_ATTRIBUTE_VALUE_REMOVED" +) diff --git a/apis/mq/v1alpha1/zz_generated.deepcopy.go b/apis/mq/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 0000000000..25a4579433 --- /dev/null +++ b/apis/mq/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,1066 @@ +// +build !ignore_autogenerated + +/* +Copyright 2020 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AvailabilityZone) DeepCopyInto(out *AvailabilityZone) { + *out = *in + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AvailabilityZone. +func (in *AvailabilityZone) DeepCopy() *AvailabilityZone { + if in == nil { + return nil + } + out := new(AvailabilityZone) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Broker) DeepCopyInto(out *Broker) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Broker. +func (in *Broker) DeepCopy() *Broker { + if in == nil { + return nil + } + out := new(Broker) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Broker) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BrokerEngineType) DeepCopyInto(out *BrokerEngineType) { + *out = *in + if in.EngineType != nil { + in, out := &in.EngineType, &out.EngineType + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerEngineType. +func (in *BrokerEngineType) DeepCopy() *BrokerEngineType { + if in == nil { + return nil + } + out := new(BrokerEngineType) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BrokerInstance) DeepCopyInto(out *BrokerInstance) { + *out = *in + if in.ConsoleURL != nil { + in, out := &in.ConsoleURL, &out.ConsoleURL + *out = new(string) + **out = **in + } + if in.Endpoints != nil { + in, out := &in.Endpoints, &out.Endpoints + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } + if in.IPAddress != nil { + in, out := &in.IPAddress, &out.IPAddress + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerInstance. +func (in *BrokerInstance) DeepCopy() *BrokerInstance { + if in == nil { + return nil + } + out := new(BrokerInstance) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BrokerInstanceOption) DeepCopyInto(out *BrokerInstanceOption) { + *out = *in + if in.EngineType != nil { + in, out := &in.EngineType, &out.EngineType + *out = new(string) + **out = **in + } + if in.HostInstanceType != nil { + in, out := &in.HostInstanceType, &out.HostInstanceType + *out = new(string) + **out = **in + } + if in.StorageType != nil { + in, out := &in.StorageType, &out.StorageType + *out = new(string) + **out = **in + } + if in.SupportedEngineVersions != nil { + in, out := &in.SupportedEngineVersions, &out.SupportedEngineVersions + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerInstanceOption. +func (in *BrokerInstanceOption) DeepCopy() *BrokerInstanceOption { + if in == nil { + return nil + } + out := new(BrokerInstanceOption) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BrokerList) DeepCopyInto(out *BrokerList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Broker, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerList. +func (in *BrokerList) DeepCopy() *BrokerList { + if in == nil { + return nil + } + out := new(BrokerList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BrokerList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BrokerObservation) DeepCopyInto(out *BrokerObservation) { + *out = *in + if in.BrokerARN != nil { + in, out := &in.BrokerARN, &out.BrokerARN + *out = new(string) + **out = **in + } + if in.BrokerID != nil { + in, out := &in.BrokerID, &out.BrokerID + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerObservation. +func (in *BrokerObservation) DeepCopy() *BrokerObservation { + if in == nil { + return nil + } + out := new(BrokerObservation) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BrokerParameters) DeepCopyInto(out *BrokerParameters) { + *out = *in + if in.AuthenticationStrategy != nil { + in, out := &in.AuthenticationStrategy, &out.AuthenticationStrategy + *out = new(string) + **out = **in + } + if in.AutoMinorVersionUpgrade != nil { + in, out := &in.AutoMinorVersionUpgrade, &out.AutoMinorVersionUpgrade + *out = new(bool) + **out = **in + } + if in.BrokerName != nil { + in, out := &in.BrokerName, &out.BrokerName + *out = new(string) + **out = **in + } + if in.Configuration != nil { + in, out := &in.Configuration, &out.Configuration + *out = new(ConfigurationID) + (*in).DeepCopyInto(*out) + } + if in.CreatorRequestID != nil { + in, out := &in.CreatorRequestID, &out.CreatorRequestID + *out = new(string) + **out = **in + } + if in.DeploymentMode != nil { + in, out := &in.DeploymentMode, &out.DeploymentMode + *out = new(string) + **out = **in + } + if in.EncryptionOptions != nil { + in, out := &in.EncryptionOptions, &out.EncryptionOptions + *out = new(EncryptionOptions) + (*in).DeepCopyInto(*out) + } + if in.EngineType != nil { + in, out := &in.EngineType, &out.EngineType + *out = new(string) + **out = **in + } + if in.EngineVersion != nil { + in, out := &in.EngineVersion, &out.EngineVersion + *out = new(string) + **out = **in + } + if in.HostInstanceType != nil { + in, out := &in.HostInstanceType, &out.HostInstanceType + *out = new(string) + **out = **in + } + if in.LDAPServerMetadata != nil { + in, out := &in.LDAPServerMetadata, &out.LDAPServerMetadata + *out = new(LDAPServerMetadataInput) + (*in).DeepCopyInto(*out) + } + if in.Logs != nil { + in, out := &in.Logs, &out.Logs + *out = new(Logs) + (*in).DeepCopyInto(*out) + } + if in.MaintenanceWindowStartTime != nil { + in, out := &in.MaintenanceWindowStartTime, &out.MaintenanceWindowStartTime + *out = new(WeeklyStartTime) + (*in).DeepCopyInto(*out) + } + if in.PubliclyAccessible != nil { + in, out := &in.PubliclyAccessible, &out.PubliclyAccessible + *out = new(bool) + **out = **in + } + if in.SecurityGroups != nil { + in, out := &in.SecurityGroups, &out.SecurityGroups + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } + if in.StorageType != nil { + in, out := &in.StorageType, &out.StorageType + *out = new(string) + **out = **in + } + if in.SubnetIDs != nil { + in, out := &in.SubnetIDs, &out.SubnetIDs + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } + if in.Tags != nil { + in, out := &in.Tags, &out.Tags + *out = make(map[string]*string, len(*in)) + for key, val := range *in { + var outVal *string + if val == nil { + (*out)[key] = nil + } else { + in, out := &val, &outVal + *out = new(string) + **out = **in + } + (*out)[key] = outVal + } + } + if in.Users != nil { + in, out := &in.Users, &out.Users + *out = make([]*User, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(User) + (*in).DeepCopyInto(*out) + } + } + } + out.CustomBrokerParameters = in.CustomBrokerParameters +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerParameters. +func (in *BrokerParameters) DeepCopy() *BrokerParameters { + if in == nil { + return nil + } + out := new(BrokerParameters) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BrokerSpec) DeepCopyInto(out *BrokerSpec) { + *out = *in + in.ResourceSpec.DeepCopyInto(&out.ResourceSpec) + in.ForProvider.DeepCopyInto(&out.ForProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerSpec. +func (in *BrokerSpec) DeepCopy() *BrokerSpec { + if in == nil { + return nil + } + out := new(BrokerSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BrokerStatus) DeepCopyInto(out *BrokerStatus) { + *out = *in + in.ResourceStatus.DeepCopyInto(&out.ResourceStatus) + in.AtProvider.DeepCopyInto(&out.AtProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerStatus. +func (in *BrokerStatus) DeepCopy() *BrokerStatus { + if in == nil { + return nil + } + out := new(BrokerStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BrokerSummary) DeepCopyInto(out *BrokerSummary) { + *out = *in + if in.BrokerARN != nil { + in, out := &in.BrokerARN, &out.BrokerARN + *out = new(string) + **out = **in + } + if in.BrokerID != nil { + in, out := &in.BrokerID, &out.BrokerID + *out = new(string) + **out = **in + } + if in.BrokerName != nil { + in, out := &in.BrokerName, &out.BrokerName + *out = new(string) + **out = **in + } + if in.BrokerState != nil { + in, out := &in.BrokerState, &out.BrokerState + *out = new(string) + **out = **in + } + if in.Created != nil { + in, out := &in.Created, &out.Created + *out = (*in).DeepCopy() + } + if in.DeploymentMode != nil { + in, out := &in.DeploymentMode, &out.DeploymentMode + *out = new(string) + **out = **in + } + if in.EngineType != nil { + in, out := &in.EngineType, &out.EngineType + *out = new(string) + **out = **in + } + if in.HostInstanceType != nil { + in, out := &in.HostInstanceType, &out.HostInstanceType + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerSummary. +func (in *BrokerSummary) DeepCopy() *BrokerSummary { + if in == nil { + return nil + } + out := new(BrokerSummary) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Configuration) DeepCopyInto(out *Configuration) { + *out = *in + if in.ARN != nil { + in, out := &in.ARN, &out.ARN + *out = new(string) + **out = **in + } + if in.AuthenticationStrategy != nil { + in, out := &in.AuthenticationStrategy, &out.AuthenticationStrategy + *out = new(string) + **out = **in + } + if in.Created != nil { + in, out := &in.Created, &out.Created + *out = (*in).DeepCopy() + } + if in.Description != nil { + in, out := &in.Description, &out.Description + *out = new(string) + **out = **in + } + if in.EngineType != nil { + in, out := &in.EngineType, &out.EngineType + *out = new(string) + **out = **in + } + if in.EngineVersion != nil { + in, out := &in.EngineVersion, &out.EngineVersion + *out = new(string) + **out = **in + } + if in.ID != nil { + in, out := &in.ID, &out.ID + *out = new(string) + **out = **in + } + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } + if in.Tags != nil { + in, out := &in.Tags, &out.Tags + *out = make(map[string]*string, len(*in)) + for key, val := range *in { + var outVal *string + if val == nil { + (*out)[key] = nil + } else { + in, out := &val, &outVal + *out = new(string) + **out = **in + } + (*out)[key] = outVal + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Configuration. +func (in *Configuration) DeepCopy() *Configuration { + if in == nil { + return nil + } + out := new(Configuration) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConfigurationID) DeepCopyInto(out *ConfigurationID) { + *out = *in + if in.ID != nil { + in, out := &in.ID, &out.ID + *out = new(string) + **out = **in + } + if in.Revision != nil { + in, out := &in.Revision, &out.Revision + *out = new(int64) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConfigurationID. +func (in *ConfigurationID) DeepCopy() *ConfigurationID { + if in == nil { + return nil + } + out := new(ConfigurationID) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConfigurationRevision) DeepCopyInto(out *ConfigurationRevision) { + *out = *in + if in.Created != nil { + in, out := &in.Created, &out.Created + *out = (*in).DeepCopy() + } + if in.Description != nil { + in, out := &in.Description, &out.Description + *out = new(string) + **out = **in + } + if in.Revision != nil { + in, out := &in.Revision, &out.Revision + *out = new(int64) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConfigurationRevision. +func (in *ConfigurationRevision) DeepCopy() *ConfigurationRevision { + if in == nil { + return nil + } + out := new(ConfigurationRevision) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Configurations) DeepCopyInto(out *Configurations) { + *out = *in + if in.Current != nil { + in, out := &in.Current, &out.Current + *out = new(ConfigurationID) + (*in).DeepCopyInto(*out) + } + if in.History != nil { + in, out := &in.History, &out.History + *out = make([]*ConfigurationID, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(ConfigurationID) + (*in).DeepCopyInto(*out) + } + } + } + if in.Pending != nil { + in, out := &in.Pending, &out.Pending + *out = new(ConfigurationID) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Configurations. +func (in *Configurations) DeepCopy() *Configurations { + if in == nil { + return nil + } + out := new(Configurations) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CustomBrokerParameters) DeepCopyInto(out *CustomBrokerParameters) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomBrokerParameters. +func (in *CustomBrokerParameters) DeepCopy() *CustomBrokerParameters { + if in == nil { + return nil + } + out := new(CustomBrokerParameters) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *EncryptionOptions) DeepCopyInto(out *EncryptionOptions) { + *out = *in + if in.KMSKeyID != nil { + in, out := &in.KMSKeyID, &out.KMSKeyID + *out = new(string) + **out = **in + } + if in.UseAWSOwnedKey != nil { + in, out := &in.UseAWSOwnedKey, &out.UseAWSOwnedKey + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EncryptionOptions. +func (in *EncryptionOptions) DeepCopy() *EncryptionOptions { + if in == nil { + return nil + } + out := new(EncryptionOptions) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *EngineVersion) DeepCopyInto(out *EngineVersion) { + *out = *in + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EngineVersion. +func (in *EngineVersion) DeepCopy() *EngineVersion { + if in == nil { + return nil + } + out := new(EngineVersion) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LDAPServerMetadataInput) DeepCopyInto(out *LDAPServerMetadataInput) { + *out = *in + if in.Hosts != nil { + in, out := &in.Hosts, &out.Hosts + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } + if in.RoleBase != nil { + in, out := &in.RoleBase, &out.RoleBase + *out = new(string) + **out = **in + } + if in.RoleName != nil { + in, out := &in.RoleName, &out.RoleName + *out = new(string) + **out = **in + } + if in.RoleSearchMatching != nil { + in, out := &in.RoleSearchMatching, &out.RoleSearchMatching + *out = new(string) + **out = **in + } + if in.RoleSearchSubtree != nil { + in, out := &in.RoleSearchSubtree, &out.RoleSearchSubtree + *out = new(bool) + **out = **in + } + if in.ServiceAccountPassword != nil { + in, out := &in.ServiceAccountPassword, &out.ServiceAccountPassword + *out = new(string) + **out = **in + } + if in.ServiceAccountUsername != nil { + in, out := &in.ServiceAccountUsername, &out.ServiceAccountUsername + *out = new(string) + **out = **in + } + if in.UserBase != nil { + in, out := &in.UserBase, &out.UserBase + *out = new(string) + **out = **in + } + if in.UserRoleName != nil { + in, out := &in.UserRoleName, &out.UserRoleName + *out = new(string) + **out = **in + } + if in.UserSearchMatching != nil { + in, out := &in.UserSearchMatching, &out.UserSearchMatching + *out = new(string) + **out = **in + } + if in.UserSearchSubtree != nil { + in, out := &in.UserSearchSubtree, &out.UserSearchSubtree + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LDAPServerMetadataInput. +func (in *LDAPServerMetadataInput) DeepCopy() *LDAPServerMetadataInput { + if in == nil { + return nil + } + out := new(LDAPServerMetadataInput) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LDAPServerMetadataOutput) DeepCopyInto(out *LDAPServerMetadataOutput) { + *out = *in + if in.Hosts != nil { + in, out := &in.Hosts, &out.Hosts + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } + if in.RoleBase != nil { + in, out := &in.RoleBase, &out.RoleBase + *out = new(string) + **out = **in + } + if in.RoleName != nil { + in, out := &in.RoleName, &out.RoleName + *out = new(string) + **out = **in + } + if in.RoleSearchMatching != nil { + in, out := &in.RoleSearchMatching, &out.RoleSearchMatching + *out = new(string) + **out = **in + } + if in.RoleSearchSubtree != nil { + in, out := &in.RoleSearchSubtree, &out.RoleSearchSubtree + *out = new(bool) + **out = **in + } + if in.ServiceAccountUsername != nil { + in, out := &in.ServiceAccountUsername, &out.ServiceAccountUsername + *out = new(string) + **out = **in + } + if in.UserBase != nil { + in, out := &in.UserBase, &out.UserBase + *out = new(string) + **out = **in + } + if in.UserRoleName != nil { + in, out := &in.UserRoleName, &out.UserRoleName + *out = new(string) + **out = **in + } + if in.UserSearchMatching != nil { + in, out := &in.UserSearchMatching, &out.UserSearchMatching + *out = new(string) + **out = **in + } + if in.UserSearchSubtree != nil { + in, out := &in.UserSearchSubtree, &out.UserSearchSubtree + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LDAPServerMetadataOutput. +func (in *LDAPServerMetadataOutput) DeepCopy() *LDAPServerMetadataOutput { + if in == nil { + return nil + } + out := new(LDAPServerMetadataOutput) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Logs) DeepCopyInto(out *Logs) { + *out = *in + if in.Audit != nil { + in, out := &in.Audit, &out.Audit + *out = new(bool) + **out = **in + } + if in.General != nil { + in, out := &in.General, &out.General + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Logs. +func (in *Logs) DeepCopy() *Logs { + if in == nil { + return nil + } + out := new(Logs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LogsSummary) DeepCopyInto(out *LogsSummary) { + *out = *in + if in.Audit != nil { + in, out := &in.Audit, &out.Audit + *out = new(bool) + **out = **in + } + if in.AuditLogGroup != nil { + in, out := &in.AuditLogGroup, &out.AuditLogGroup + *out = new(string) + **out = **in + } + if in.General != nil { + in, out := &in.General, &out.General + *out = new(bool) + **out = **in + } + if in.GeneralLogGroup != nil { + in, out := &in.GeneralLogGroup, &out.GeneralLogGroup + *out = new(string) + **out = **in + } + if in.Pending != nil { + in, out := &in.Pending, &out.Pending + *out = new(PendingLogs) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogsSummary. +func (in *LogsSummary) DeepCopy() *LogsSummary { + if in == nil { + return nil + } + out := new(LogsSummary) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PendingLogs) DeepCopyInto(out *PendingLogs) { + *out = *in + if in.Audit != nil { + in, out := &in.Audit, &out.Audit + *out = new(bool) + **out = **in + } + if in.General != nil { + in, out := &in.General, &out.General + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PendingLogs. +func (in *PendingLogs) DeepCopy() *PendingLogs { + if in == nil { + return nil + } + out := new(PendingLogs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SanitizationWarning) DeepCopyInto(out *SanitizationWarning) { + *out = *in + if in.AttributeName != nil { + in, out := &in.AttributeName, &out.AttributeName + *out = new(string) + **out = **in + } + if in.ElementName != nil { + in, out := &in.ElementName, &out.ElementName + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SanitizationWarning. +func (in *SanitizationWarning) DeepCopy() *SanitizationWarning { + if in == nil { + return nil + } + out := new(SanitizationWarning) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *User) DeepCopyInto(out *User) { + *out = *in + if in.ConsoleAccess != nil { + in, out := &in.ConsoleAccess, &out.ConsoleAccess + *out = new(bool) + **out = **in + } + if in.Groups != nil { + in, out := &in.Groups, &out.Groups + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } + if in.Password != nil { + in, out := &in.Password, &out.Password + *out = new(string) + **out = **in + } + if in.Username != nil { + in, out := &in.Username, &out.Username + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new User. +func (in *User) DeepCopy() *User { + if in == nil { + return nil + } + out := new(User) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UserPendingChanges) DeepCopyInto(out *UserPendingChanges) { + *out = *in + if in.ConsoleAccess != nil { + in, out := &in.ConsoleAccess, &out.ConsoleAccess + *out = new(bool) + **out = **in + } + if in.Groups != nil { + in, out := &in.Groups, &out.Groups + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } + if in.PendingChange != nil { + in, out := &in.PendingChange, &out.PendingChange + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserPendingChanges. +func (in *UserPendingChanges) DeepCopy() *UserPendingChanges { + if in == nil { + return nil + } + out := new(UserPendingChanges) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UserSummary) DeepCopyInto(out *UserSummary) { + *out = *in + if in.PendingChange != nil { + in, out := &in.PendingChange, &out.PendingChange + *out = new(string) + **out = **in + } + if in.Username != nil { + in, out := &in.Username, &out.Username + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserSummary. +func (in *UserSummary) DeepCopy() *UserSummary { + if in == nil { + return nil + } + out := new(UserSummary) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *WeeklyStartTime) DeepCopyInto(out *WeeklyStartTime) { + *out = *in + if in.DayOfWeek != nil { + in, out := &in.DayOfWeek, &out.DayOfWeek + *out = new(string) + **out = **in + } + if in.TimeOfDay != nil { + in, out := &in.TimeOfDay, &out.TimeOfDay + *out = new(string) + **out = **in + } + if in.TimeZone != nil { + in, out := &in.TimeZone, &out.TimeZone + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WeeklyStartTime. +func (in *WeeklyStartTime) DeepCopy() *WeeklyStartTime { + if in == nil { + return nil + } + out := new(WeeklyStartTime) + in.DeepCopyInto(out) + return out +} diff --git a/apis/mq/v1alpha1/zz_generated.managed.go b/apis/mq/v1alpha1/zz_generated.managed.go new file mode 100644 index 0000000000..d1c7b3687b --- /dev/null +++ b/apis/mq/v1alpha1/zz_generated.managed.go @@ -0,0 +1,77 @@ +/* +Copyright 2020 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by angryjet. DO NOT EDIT. + +package v1alpha1 + +import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + +// GetCondition of this Broker. +func (mg *Broker) GetCondition(ct xpv1.ConditionType) xpv1.Condition { + return mg.Status.GetCondition(ct) +} + +// GetDeletionPolicy of this Broker. +func (mg *Broker) GetDeletionPolicy() xpv1.DeletionPolicy { + return mg.Spec.DeletionPolicy +} + +// GetProviderConfigReference of this Broker. +func (mg *Broker) GetProviderConfigReference() *xpv1.Reference { + return mg.Spec.ProviderConfigReference +} + +/* +GetProviderReference of this Broker. +Deprecated: Use GetProviderConfigReference. +*/ +func (mg *Broker) GetProviderReference() *xpv1.Reference { + return mg.Spec.ProviderReference +} + +// GetWriteConnectionSecretToReference of this Broker. +func (mg *Broker) GetWriteConnectionSecretToReference() *xpv1.SecretReference { + return mg.Spec.WriteConnectionSecretToReference +} + +// SetConditions of this Broker. +func (mg *Broker) SetConditions(c ...xpv1.Condition) { + mg.Status.SetConditions(c...) +} + +// SetDeletionPolicy of this Broker. +func (mg *Broker) SetDeletionPolicy(r xpv1.DeletionPolicy) { + mg.Spec.DeletionPolicy = r +} + +// SetProviderConfigReference of this Broker. +func (mg *Broker) SetProviderConfigReference(r *xpv1.Reference) { + mg.Spec.ProviderConfigReference = r +} + +/* +SetProviderReference of this Broker. +Deprecated: Use SetProviderConfigReference. +*/ +func (mg *Broker) SetProviderReference(r *xpv1.Reference) { + mg.Spec.ProviderReference = r +} + +// SetWriteConnectionSecretToReference of this Broker. +func (mg *Broker) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { + mg.Spec.WriteConnectionSecretToReference = r +} diff --git a/apis/mq/v1alpha1/zz_generated.managedlist.go b/apis/mq/v1alpha1/zz_generated.managedlist.go new file mode 100644 index 0000000000..7bf7ad3364 --- /dev/null +++ b/apis/mq/v1alpha1/zz_generated.managedlist.go @@ -0,0 +1,30 @@ +/* +Copyright 2020 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by angryjet. DO NOT EDIT. + +package v1alpha1 + +import resource "github.com/crossplane/crossplane-runtime/pkg/resource" + +// GetItems of this BrokerList. +func (l *BrokerList) GetItems() []resource.Managed { + items := make([]resource.Managed, len(l.Items)) + for i := range l.Items { + items[i] = &l.Items[i] + } + return items +} diff --git a/apis/mq/v1alpha1/zz_groupversion_info.go b/apis/mq/v1alpha1/zz_groupversion_info.go new file mode 100644 index 0000000000..46e93d7441 --- /dev/null +++ b/apis/mq/v1alpha1/zz_groupversion_info.go @@ -0,0 +1,41 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +// Package type metadata. +const ( + Group = "mq.aws.crossplane.io" + Version = "v1alpha1" +) + +var ( + // GroupVersion is the API Group Version used to register the objects + GroupVersion = schema.GroupVersion{Group: Group, Version: Version} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/apis/mq/v1alpha1/zz_types.go b/apis/mq/v1alpha1/zz_types.go new file mode 100644 index 0000000000..8617c0fdaf --- /dev/null +++ b/apis/mq/v1alpha1/zz_types.go @@ -0,0 +1,243 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// Hack to avoid import errors during build... +var ( + _ = &metav1.Time{} +) + +type AvailabilityZone struct { + Name *string `json:"name,omitempty"` +} + +type BrokerEngineType struct { + // The type of broker engine. Note: Currently, Amazon MQ supports ActiveMQ and + // RabbitMQ. + EngineType *string `json:"engineType,omitempty"` +} + +type BrokerInstance struct { + ConsoleURL *string `json:"consoleURL,omitempty"` + + Endpoints []*string `json:"endpoints,omitempty"` + + IPAddress *string `json:"ipAddress,omitempty"` +} + +type BrokerInstanceOption struct { + // The type of broker engine. Note: Currently, Amazon MQ supports ActiveMQ and + // RabbitMQ. + EngineType *string `json:"engineType,omitempty"` + + HostInstanceType *string `json:"hostInstanceType,omitempty"` + // The storage type of the broker. EFS is currently not Supported for RabbitMQ + // engine type. + StorageType *string `json:"storageType,omitempty"` + + SupportedEngineVersions []*string `json:"supportedEngineVersions,omitempty"` +} + +type BrokerSummary struct { + BrokerARN *string `json:"brokerARN,omitempty"` + + BrokerID *string `json:"brokerID,omitempty"` + + BrokerName *string `json:"brokerName,omitempty"` + // The status of the broker. + BrokerState *string `json:"brokerState,omitempty"` + + Created *metav1.Time `json:"created,omitempty"` + // The deployment mode of the broker. + DeploymentMode *string `json:"deploymentMode,omitempty"` + // The type of broker engine. Note: Currently, Amazon MQ supports ActiveMQ and + // RabbitMQ. + EngineType *string `json:"engineType,omitempty"` + + HostInstanceType *string `json:"hostInstanceType,omitempty"` +} + +type Configuration struct { + ARN *string `json:"arn,omitempty"` + // The authentication strategy used to secure the broker. + AuthenticationStrategy *string `json:"authenticationStrategy,omitempty"` + + Created *metav1.Time `json:"created,omitempty"` + + Description *string `json:"description,omitempty"` + // The type of broker engine. Note: Currently, Amazon MQ supports ActiveMQ and + // RabbitMQ. + EngineType *string `json:"engineType,omitempty"` + + EngineVersion *string `json:"engineVersion,omitempty"` + + ID *string `json:"id,omitempty"` + + Name *string `json:"name,omitempty"` + + Tags map[string]*string `json:"tags,omitempty"` +} + +type ConfigurationID struct { + ID *string `json:"id,omitempty"` + + Revision *int64 `json:"revision,omitempty"` +} + +type ConfigurationRevision struct { + Created *metav1.Time `json:"created,omitempty"` + + Description *string `json:"description,omitempty"` + + Revision *int64 `json:"revision,omitempty"` +} + +type Configurations struct { + // A list of information about the configuration. Does not apply to RabbitMQ + // brokers. + Current *ConfigurationID `json:"current,omitempty"` + + History []*ConfigurationID `json:"history,omitempty"` + // A list of information about the configuration. Does not apply to RabbitMQ + // brokers. + Pending *ConfigurationID `json:"pending,omitempty"` +} + +type EncryptionOptions struct { + KMSKeyID *string `json:"kmsKeyID,omitempty"` + + UseAWSOwnedKey *bool `json:"useAWSOwnedKey,omitempty"` +} + +type EngineVersion struct { + Name *string `json:"name,omitempty"` +} + +type LDAPServerMetadataInput struct { + Hosts []*string `json:"hosts,omitempty"` + + RoleBase *string `json:"roleBase,omitempty"` + + RoleName *string `json:"roleName,omitempty"` + + RoleSearchMatching *string `json:"roleSearchMatching,omitempty"` + + RoleSearchSubtree *bool `json:"roleSearchSubtree,omitempty"` + + ServiceAccountPassword *string `json:"serviceAccountPassword,omitempty"` + + ServiceAccountUsername *string `json:"serviceAccountUsername,omitempty"` + + UserBase *string `json:"userBase,omitempty"` + + UserRoleName *string `json:"userRoleName,omitempty"` + + UserSearchMatching *string `json:"userSearchMatching,omitempty"` + + UserSearchSubtree *bool `json:"userSearchSubtree,omitempty"` +} + +type LDAPServerMetadataOutput struct { + Hosts []*string `json:"hosts,omitempty"` + + RoleBase *string `json:"roleBase,omitempty"` + + RoleName *string `json:"roleName,omitempty"` + + RoleSearchMatching *string `json:"roleSearchMatching,omitempty"` + + RoleSearchSubtree *bool `json:"roleSearchSubtree,omitempty"` + + ServiceAccountUsername *string `json:"serviceAccountUsername,omitempty"` + + UserBase *string `json:"userBase,omitempty"` + + UserRoleName *string `json:"userRoleName,omitempty"` + + UserSearchMatching *string `json:"userSearchMatching,omitempty"` + + UserSearchSubtree *bool `json:"userSearchSubtree,omitempty"` +} + +type Logs struct { + Audit *bool `json:"audit,omitempty"` + + General *bool `json:"general,omitempty"` +} + +type LogsSummary struct { + Audit *bool `json:"audit,omitempty"` + + AuditLogGroup *string `json:"auditLogGroup,omitempty"` + + General *bool `json:"general,omitempty"` + + GeneralLogGroup *string `json:"generalLogGroup,omitempty"` + // The list of information about logs to be enabled for the specified broker. + Pending *PendingLogs `json:"pending,omitempty"` +} + +type PendingLogs struct { + Audit *bool `json:"audit,omitempty"` + + General *bool `json:"general,omitempty"` +} + +type SanitizationWarning struct { + AttributeName *string `json:"attributeName,omitempty"` + + ElementName *string `json:"elementName,omitempty"` +} + +type User struct { + ConsoleAccess *bool `json:"consoleAccess,omitempty"` + + Groups []*string `json:"groups,omitempty"` + + Password *string `json:"password,omitempty"` + + Username *string `json:"username,omitempty"` +} + +type UserPendingChanges struct { + ConsoleAccess *bool `json:"consoleAccess,omitempty"` + + Groups []*string `json:"groups,omitempty"` + // The type of change pending for the ActiveMQ user. + PendingChange *string `json:"pendingChange,omitempty"` +} + +type UserSummary struct { + // The type of change pending for the ActiveMQ user. + PendingChange *string `json:"pendingChange,omitempty"` + + Username *string `json:"username,omitempty"` +} + +type WeeklyStartTime struct { + DayOfWeek *string `json:"dayOfWeek,omitempty"` + + TimeOfDay *string `json:"timeOfDay,omitempty"` + + TimeZone *string `json:"timeZone,omitempty"` +} diff --git a/package/crds/mq.aws.crossplane.io_brokers.yaml b/package/crds/mq.aws.crossplane.io_brokers.yaml new file mode 100644 index 0000000000..5a14a16284 --- /dev/null +++ b/package/crds/mq.aws.crossplane.io_brokers.yaml @@ -0,0 +1,256 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.4.0 + creationTimestamp: null + name: brokers.mq.aws.crossplane.io +spec: + group: mq.aws.crossplane.io + names: + categories: + - crossplane + - managed + - aws + kind: Broker + listKind: BrokerList + plural: brokers + singular: broker + scope: Cluster + versions: + - additionalPrinterColumns: + - jsonPath: .status.conditions[?(@.type=='Ready')].status + name: READY + type: string + - jsonPath: .status.conditions[?(@.type=='Synced')].status + name: SYNCED + type: string + - jsonPath: .metadata.annotations.crossplane\.io/external-name + name: EXTERNAL-NAME + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: Broker is the Schema for the Brokers API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: BrokerSpec defines the desired state of Broker + properties: + deletionPolicy: + default: Delete + description: DeletionPolicy specifies what will happen to the underlying external when this managed resource is deleted - either "Delete" or "Orphan" the external resource. + enum: + - Orphan + - Delete + type: string + forProvider: + description: BrokerParameters defines the desired state of Broker + properties: + authenticationStrategy: + type: string + autoMinorVersionUpgrade: + type: boolean + brokerName: + type: string + configuration: + properties: + id: + type: string + revision: + format: int64 + type: integer + type: object + creatorRequestID: + type: string + deploymentMode: + type: string + encryptionOptions: + properties: + kmsKeyID: + type: string + useAWSOwnedKey: + type: boolean + type: object + engineType: + type: string + engineVersion: + type: string + hostInstanceType: + type: string + ldapServerMetadata: + properties: + hosts: + items: + type: string + type: array + roleBase: + type: string + roleName: + type: string + roleSearchMatching: + type: string + roleSearchSubtree: + type: boolean + serviceAccountPassword: + type: string + serviceAccountUsername: + type: string + userBase: + type: string + userRoleName: + type: string + userSearchMatching: + type: string + userSearchSubtree: + type: boolean + type: object + logs: + properties: + audit: + type: boolean + general: + type: boolean + type: object + maintenanceWindowStartTime: + properties: + dayOfWeek: + type: string + timeOfDay: + type: string + timeZone: + type: string + type: object + publiclyAccessible: + type: boolean + region: + description: Region is which region the Broker will be created. + type: string + securityGroups: + items: + type: string + type: array + storageType: + type: string + subnetIDs: + items: + type: string + type: array + tags: + additionalProperties: + type: string + type: object + users: + items: + properties: + consoleAccess: + type: boolean + groups: + items: + type: string + type: array + password: + type: string + username: + type: string + type: object + type: array + required: + - region + type: object + providerConfigRef: + default: + name: default + description: ProviderConfigReference specifies how the provider that will be used to create, observe, update, and delete this managed resource should be configured. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + providerRef: + description: 'ProviderReference specifies the provider that will be used to create, observe, update, and delete this managed resource. Deprecated: Please use ProviderConfigReference, i.e. `providerConfigRef`' + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + writeConnectionSecretToRef: + description: WriteConnectionSecretToReference specifies the namespace and name of a Secret to which any connection details for this managed resource should be written. Connection details frequently include the endpoint, username, and password required to connect to the managed resource. + properties: + name: + description: Name of the secret. + type: string + namespace: + description: Namespace of the secret. + type: string + required: + - name + - namespace + type: object + required: + - forProvider + type: object + status: + description: BrokerStatus defines the observed state of Broker. + properties: + atProvider: + description: BrokerObservation defines the observed state of Broker + properties: + brokerARN: + type: string + brokerID: + type: string + type: object + conditions: + description: Conditions of the resource. + items: + description: A Condition that may apply to a resource. + properties: + lastTransitionTime: + description: LastTransitionTime is the last time this condition transitioned from one status to another. + format: date-time + type: string + message: + description: A Message containing details about this condition's last transition from one status to another, if any. + type: string + reason: + description: A Reason for this condition's last transition from one status to another. + type: string + status: + description: Status of this condition; is it currently True, False, or Unknown? + type: string + type: + description: Type of this condition. At most one of each condition type may apply to a resource at any point in time. + type: string + required: + - lastTransitionTime + - reason + - status + - type + type: object + type: array + type: object + required: + - spec + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/pkg/controller/aws.go b/pkg/controller/aws.go index 865d6db097..076b7aa4d8 100644 --- a/pkg/controller/aws.go +++ b/pkg/controller/aws.go @@ -93,6 +93,7 @@ import ( kafkacluster "github.com/crossplane/provider-aws/pkg/controller/kafka/cluster" "github.com/crossplane/provider-aws/pkg/controller/kms/key" "github.com/crossplane/provider-aws/pkg/controller/lambda/function" + "github.com/crossplane/provider-aws/pkg/controller/mq/broker" "github.com/crossplane/provider-aws/pkg/controller/notification/snssubscription" "github.com/crossplane/provider-aws/pkg/controller/notification/snstopic" "github.com/crossplane/provider-aws/pkg/controller/rds/dbcluster" @@ -213,6 +214,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll ti glueDatabase.SetupDatabase, gluecrawler.SetupCrawler, glueclassifier.SetupClassifier, + broker.SetupBroker, } { if err := setup(mgr, l, rl, poll); err != nil { return err diff --git a/pkg/controller/mq/broker/setup.go b/pkg/controller/mq/broker/setup.go new file mode 100644 index 0000000000..086d0badcb --- /dev/null +++ b/pkg/controller/mq/broker/setup.go @@ -0,0 +1,31 @@ +package broker + +import ( + "k8s.io/client-go/util/workqueue" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/controller" + + "github.com/crossplane/crossplane-runtime/pkg/event" + "github.com/crossplane/crossplane-runtime/pkg/logging" + "github.com/crossplane/crossplane-runtime/pkg/ratelimiter" + "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" + "github.com/crossplane/crossplane-runtime/pkg/resource" + + svcapitypes "github.com/crossplane/provider-aws/apis/mq/v1alpha1" +) + +// SetupMQ adds a controller that reconciles Stage. +func SetupMQ(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error { + name := managed.ControllerName(svcapitypes.MQGroupKind) + return ctrl.NewControllerManagedBy(mgr). + Named(name). + WithOptions(controller.Options{ + RateLimiter: ratelimiter.NewDefaultManagedRateLimiter(rl), + }). + For(&svcapitypes.MQ{}). + Complete(managed.NewReconciler(mgr, + resource.ManagedKind(svcapitypes.MQGroupVersionKind), + managed.WithExternalConnecter(&connector{kube: mgr.GetClient()}), + managed.WithLogger(l.WithValues("controller", name)), + managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))))) +} diff --git a/pkg/controller/mq/broker/zz_controller.go b/pkg/controller/mq/broker/zz_controller.go new file mode 100644 index 0000000000..c8b3928312 --- /dev/null +++ b/pkg/controller/mq/broker/zz_controller.go @@ -0,0 +1,231 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package broker + +import ( + "context" + + svcapi "github.com/aws/aws-sdk-go/service/mq" + svcsdk "github.com/aws/aws-sdk-go/service/mq" + svcsdkapi "github.com/aws/aws-sdk-go/service/mq/mqiface" + "github.com/google/go-cmp/cmp" + "github.com/pkg/errors" + "sigs.k8s.io/controller-runtime/pkg/client" + + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + "github.com/crossplane/crossplane-runtime/pkg/meta" + "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" + cpresource "github.com/crossplane/crossplane-runtime/pkg/resource" + + svcapitypes "github.com/crossplane/provider-aws/apis/mq/v1alpha1" + awsclient "github.com/crossplane/provider-aws/pkg/clients" +) + +const ( + errUnexpectedObject = "managed resource is not an Broker resource" + + errCreateSession = "cannot create a new session" + errCreate = "cannot create Broker in AWS" + errUpdate = "cannot update Broker in AWS" + errDescribe = "failed to describe Broker" + errDelete = "failed to delete Broker" +) + +type connector struct { + kube client.Client + opts []option +} + +func (c *connector) Connect(ctx context.Context, mg cpresource.Managed) (managed.ExternalClient, error) { + cr, ok := mg.(*svcapitypes.Broker) + if !ok { + return nil, errors.New(errUnexpectedObject) + } + sess, err := awsclient.GetConfigV1(ctx, c.kube, mg, cr.Spec.ForProvider.Region) + if err != nil { + return nil, errors.Wrap(err, errCreateSession) + } + return newExternal(c.kube, svcapi.New(sess), c.opts), nil +} + +func (e *external) Observe(ctx context.Context, mg cpresource.Managed) (managed.ExternalObservation, error) { + cr, ok := mg.(*svcapitypes.Broker) + if !ok { + return managed.ExternalObservation{}, errors.New(errUnexpectedObject) + } + if meta.GetExternalName(cr) == "" { + return managed.ExternalObservation{ + ResourceExists: false, + }, nil + } + input := GenerateDescribeBrokerInput(cr) + if err := e.preObserve(ctx, cr, input); err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, "pre-observe failed") + } + resp, err := e.client.DescribeBrokerWithContext(ctx, input) + if err != nil { + return managed.ExternalObservation{ResourceExists: false}, awsclient.Wrap(cpresource.Ignore(IsNotFound, err), errDescribe) + } + currentSpec := cr.Spec.ForProvider.DeepCopy() + if err := e.lateInitialize(&cr.Spec.ForProvider, resp); err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, "late-init failed") + } + GenerateBroker(resp).Status.AtProvider.DeepCopyInto(&cr.Status.AtProvider) + + upToDate, err := e.isUpToDate(cr, resp) + if err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, "isUpToDate check failed") + } + return e.postObserve(ctx, cr, resp, managed.ExternalObservation{ + ResourceExists: true, + ResourceUpToDate: upToDate, + ResourceLateInitialized: !cmp.Equal(&cr.Spec.ForProvider, currentSpec), + }, nil) +} + +func (e *external) Create(ctx context.Context, mg cpresource.Managed) (managed.ExternalCreation, error) { + cr, ok := mg.(*svcapitypes.Broker) + if !ok { + return managed.ExternalCreation{}, errors.New(errUnexpectedObject) + } + cr.Status.SetConditions(xpv1.Creating()) + input := GenerateCreateBrokerRequest(cr) + if err := e.preCreate(ctx, cr, input); err != nil { + return managed.ExternalCreation{}, errors.Wrap(err, "pre-create failed") + } + resp, err := e.client.CreateBrokerWithContext(ctx, input) + if err != nil { + return managed.ExternalCreation{}, awsclient.Wrap(err, errCreate) + } + + if resp.BrokerArn != nil { + cr.Status.AtProvider.BrokerARN = resp.BrokerArn + } else { + cr.Status.AtProvider.BrokerARN = nil + } + if resp.BrokerId != nil { + cr.Status.AtProvider.BrokerID = resp.BrokerId + } else { + cr.Status.AtProvider.BrokerID = nil + } + + return e.postCreate(ctx, cr, resp, managed.ExternalCreation{}, err) +} + +func (e *external) Update(ctx context.Context, mg cpresource.Managed) (managed.ExternalUpdate, error) { + cr, ok := mg.(*svcapitypes.Broker) + if !ok { + return managed.ExternalUpdate{}, errors.New(errUnexpectedObject) + } + input := GenerateUpdateBrokerRequest(cr) + if err := e.preUpdate(ctx, cr, input); err != nil { + return managed.ExternalUpdate{}, errors.Wrap(err, "pre-update failed") + } + resp, err := e.client.UpdateBrokerWithContext(ctx, input) + return e.postUpdate(ctx, cr, resp, managed.ExternalUpdate{}, awsclient.Wrap(err, errUpdate)) +} + +func (e *external) Delete(ctx context.Context, mg cpresource.Managed) error { + cr, ok := mg.(*svcapitypes.Broker) + if !ok { + return errors.New(errUnexpectedObject) + } + cr.Status.SetConditions(xpv1.Deleting()) + input := GenerateDeleteBrokerInput(cr) + ignore, err := e.preDelete(ctx, cr, input) + if err != nil { + return errors.Wrap(err, "pre-delete failed") + } + if ignore { + return nil + } + resp, err := e.client.DeleteBrokerWithContext(ctx, input) + return e.postDelete(ctx, cr, resp, awsclient.Wrap(cpresource.Ignore(IsNotFound, err), errDelete)) +} + +type option func(*external) + +func newExternal(kube client.Client, client svcsdkapi.MQAPI, opts []option) *external { + e := &external{ + kube: kube, + client: client, + preObserve: nopPreObserve, + postObserve: nopPostObserve, + lateInitialize: nopLateInitialize, + isUpToDate: alwaysUpToDate, + preCreate: nopPreCreate, + postCreate: nopPostCreate, + preDelete: nopPreDelete, + postDelete: nopPostDelete, + preUpdate: nopPreUpdate, + postUpdate: nopPostUpdate, + } + for _, f := range opts { + f(e) + } + return e +} + +type external struct { + kube client.Client + client svcsdkapi.MQAPI + preObserve func(context.Context, *svcapitypes.Broker, *svcsdk.DescribeBrokerInput) error + postObserve func(context.Context, *svcapitypes.Broker, *svcsdk.DescribeBrokerResponse, managed.ExternalObservation, error) (managed.ExternalObservation, error) + lateInitialize func(*svcapitypes.BrokerParameters, *svcsdk.DescribeBrokerResponse) error + isUpToDate func(*svcapitypes.Broker, *svcsdk.DescribeBrokerResponse) (bool, error) + preCreate func(context.Context, *svcapitypes.Broker, *svcsdk.CreateBrokerRequest) error + postCreate func(context.Context, *svcapitypes.Broker, *svcsdk.CreateBrokerResponse, managed.ExternalCreation, error) (managed.ExternalCreation, error) + preDelete func(context.Context, *svcapitypes.Broker, *svcsdk.DeleteBrokerInput) (bool, error) + postDelete func(context.Context, *svcapitypes.Broker, *svcsdk.DeleteBrokerResponse, error) error + preUpdate func(context.Context, *svcapitypes.Broker, *svcsdk.UpdateBrokerRequest) error + postUpdate func(context.Context, *svcapitypes.Broker, *svcsdk.UpdateBrokerResponse, managed.ExternalUpdate, error) (managed.ExternalUpdate, error) +} + +func nopPreObserve(context.Context, *svcapitypes.Broker, *svcsdk.DescribeBrokerInput) error { + return nil +} + +func nopPostObserve(_ context.Context, _ *svcapitypes.Broker, _ *svcsdk.DescribeBrokerResponse, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) { + return obs, err +} +func nopLateInitialize(*svcapitypes.BrokerParameters, *svcsdk.DescribeBrokerResponse) error { + return nil +} +func alwaysUpToDate(*svcapitypes.Broker, *svcsdk.DescribeBrokerResponse) (bool, error) { + return true, nil +} + +func nopPreCreate(context.Context, *svcapitypes.Broker, *svcsdk.CreateBrokerRequest) error { + return nil +} +func nopPostCreate(_ context.Context, _ *svcapitypes.Broker, _ *svcsdk.CreateBrokerResponse, cre managed.ExternalCreation, err error) (managed.ExternalCreation, error) { + return cre, err +} +func nopPreDelete(context.Context, *svcapitypes.Broker, *svcsdk.DeleteBrokerInput) (bool, error) { + return false, nil +} +func nopPostDelete(_ context.Context, _ *svcapitypes.Broker, _ *svcsdk.DeleteBrokerResponse, err error) error { + return err +} +func nopPreUpdate(context.Context, *svcapitypes.Broker, *svcsdk.UpdateBrokerRequest) error { + return nil +} +func nopPostUpdate(_ context.Context, _ *svcapitypes.Broker, _ *svcsdk.UpdateBrokerResponse, upd managed.ExternalUpdate, err error) (managed.ExternalUpdate, error) { + return upd, err +} diff --git a/pkg/controller/mq/broker/zz_conversions.go b/pkg/controller/mq/broker/zz_conversions.go new file mode 100644 index 0000000000..d61c8439fd --- /dev/null +++ b/pkg/controller/mq/broker/zz_conversions.go @@ -0,0 +1,348 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package broker + +import ( + "github.com/aws/aws-sdk-go/aws/awserr" + svcsdk "github.com/aws/aws-sdk-go/service/mq" + + svcapitypes "github.com/crossplane/provider-aws/apis/mq/v1alpha1" +) + +// NOTE(muvaf): We return pointers in case the function needs to start with an +// empty object, hence need to return a new pointer. + +// GenerateDescribeBrokerInput returns input for read +// operation. +func GenerateDescribeBrokerInput(cr *svcapitypes.Broker) *svcsdk.DescribeBrokerInput { + res := &svcsdk.DescribeBrokerInput{} + + if cr.Status.AtProvider.BrokerID != nil { + res.SetBrokerId(*cr.Status.AtProvider.BrokerID) + } + + return res +} + +// GenerateBroker returns the current state in the form of *svcapitypes.Broker. +func GenerateBroker(resp *svcsdk.DescribeBrokerResponse) *svcapitypes.Broker { + cr := &svcapitypes.Broker{} + + if resp.BrokerArn != nil { + cr.Status.AtProvider.BrokerARN = resp.BrokerArn + } else { + cr.Status.AtProvider.BrokerARN = nil + } + if resp.BrokerId != nil { + cr.Status.AtProvider.BrokerID = resp.BrokerId + } else { + cr.Status.AtProvider.BrokerID = nil + } + + return cr +} + +// GenerateCreateBrokerRequest returns a create input. +func GenerateCreateBrokerRequest(cr *svcapitypes.Broker) *svcsdk.CreateBrokerRequest { + res := &svcsdk.CreateBrokerRequest{} + + if cr.Spec.ForProvider.AuthenticationStrategy != nil { + res.SetAuthenticationStrategy(*cr.Spec.ForProvider.AuthenticationStrategy) + } + if cr.Spec.ForProvider.AutoMinorVersionUpgrade != nil { + res.SetAutoMinorVersionUpgrade(*cr.Spec.ForProvider.AutoMinorVersionUpgrade) + } + if cr.Spec.ForProvider.BrokerName != nil { + res.SetBrokerName(*cr.Spec.ForProvider.BrokerName) + } + if cr.Spec.ForProvider.Configuration != nil { + f3 := &svcsdk.ConfigurationId{} + if cr.Spec.ForProvider.Configuration.ID != nil { + f3.SetId(*cr.Spec.ForProvider.Configuration.ID) + } + if cr.Spec.ForProvider.Configuration.Revision != nil { + f3.SetRevision(*cr.Spec.ForProvider.Configuration.Revision) + } + res.SetConfiguration(f3) + } + if cr.Spec.ForProvider.CreatorRequestID != nil { + res.SetCreatorRequestId(*cr.Spec.ForProvider.CreatorRequestID) + } + if cr.Spec.ForProvider.DeploymentMode != nil { + res.SetDeploymentMode(*cr.Spec.ForProvider.DeploymentMode) + } + if cr.Spec.ForProvider.EncryptionOptions != nil { + f6 := &svcsdk.EncryptionOptions{} + if cr.Spec.ForProvider.EncryptionOptions.KMSKeyID != nil { + f6.SetKmsKeyId(*cr.Spec.ForProvider.EncryptionOptions.KMSKeyID) + } + if cr.Spec.ForProvider.EncryptionOptions.UseAWSOwnedKey != nil { + f6.SetUseAwsOwnedKey(*cr.Spec.ForProvider.EncryptionOptions.UseAWSOwnedKey) + } + res.SetEncryptionOptions(f6) + } + if cr.Spec.ForProvider.EngineType != nil { + res.SetEngineType(*cr.Spec.ForProvider.EngineType) + } + if cr.Spec.ForProvider.EngineVersion != nil { + res.SetEngineVersion(*cr.Spec.ForProvider.EngineVersion) + } + if cr.Spec.ForProvider.HostInstanceType != nil { + res.SetHostInstanceType(*cr.Spec.ForProvider.HostInstanceType) + } + if cr.Spec.ForProvider.LDAPServerMetadata != nil { + f10 := &svcsdk.LdapServerMetadataInput{} + if cr.Spec.ForProvider.LDAPServerMetadata.Hosts != nil { + f10f0 := []*string{} + for _, f10f0iter := range cr.Spec.ForProvider.LDAPServerMetadata.Hosts { + var f10f0elem string + f10f0elem = *f10f0iter + f10f0 = append(f10f0, &f10f0elem) + } + f10.SetHosts(f10f0) + } + if cr.Spec.ForProvider.LDAPServerMetadata.RoleBase != nil { + f10.SetRoleBase(*cr.Spec.ForProvider.LDAPServerMetadata.RoleBase) + } + if cr.Spec.ForProvider.LDAPServerMetadata.RoleName != nil { + f10.SetRoleName(*cr.Spec.ForProvider.LDAPServerMetadata.RoleName) + } + if cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchMatching != nil { + f10.SetRoleSearchMatching(*cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchMatching) + } + if cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchSubtree != nil { + f10.SetRoleSearchSubtree(*cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchSubtree) + } + if cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountPassword != nil { + f10.SetServiceAccountPassword(*cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountPassword) + } + if cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountUsername != nil { + f10.SetServiceAccountUsername(*cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountUsername) + } + if cr.Spec.ForProvider.LDAPServerMetadata.UserBase != nil { + f10.SetUserBase(*cr.Spec.ForProvider.LDAPServerMetadata.UserBase) + } + if cr.Spec.ForProvider.LDAPServerMetadata.UserRoleName != nil { + f10.SetUserRoleName(*cr.Spec.ForProvider.LDAPServerMetadata.UserRoleName) + } + if cr.Spec.ForProvider.LDAPServerMetadata.UserSearchMatching != nil { + f10.SetUserSearchMatching(*cr.Spec.ForProvider.LDAPServerMetadata.UserSearchMatching) + } + if cr.Spec.ForProvider.LDAPServerMetadata.UserSearchSubtree != nil { + f10.SetUserSearchSubtree(*cr.Spec.ForProvider.LDAPServerMetadata.UserSearchSubtree) + } + res.SetLdapServerMetadata(f10) + } + if cr.Spec.ForProvider.Logs != nil { + f11 := &svcsdk.Logs{} + if cr.Spec.ForProvider.Logs.Audit != nil { + f11.SetAudit(*cr.Spec.ForProvider.Logs.Audit) + } + if cr.Spec.ForProvider.Logs.General != nil { + f11.SetGeneral(*cr.Spec.ForProvider.Logs.General) + } + res.SetLogs(f11) + } + if cr.Spec.ForProvider.MaintenanceWindowStartTime != nil { + f12 := &svcsdk.WeeklyStartTime{} + if cr.Spec.ForProvider.MaintenanceWindowStartTime.DayOfWeek != nil { + f12.SetDayOfWeek(*cr.Spec.ForProvider.MaintenanceWindowStartTime.DayOfWeek) + } + if cr.Spec.ForProvider.MaintenanceWindowStartTime.TimeOfDay != nil { + f12.SetTimeOfDay(*cr.Spec.ForProvider.MaintenanceWindowStartTime.TimeOfDay) + } + if cr.Spec.ForProvider.MaintenanceWindowStartTime.TimeZone != nil { + f12.SetTimeZone(*cr.Spec.ForProvider.MaintenanceWindowStartTime.TimeZone) + } + res.SetMaintenanceWindowStartTime(f12) + } + if cr.Spec.ForProvider.PubliclyAccessible != nil { + res.SetPubliclyAccessible(*cr.Spec.ForProvider.PubliclyAccessible) + } + if cr.Spec.ForProvider.SecurityGroups != nil { + f14 := []*string{} + for _, f14iter := range cr.Spec.ForProvider.SecurityGroups { + var f14elem string + f14elem = *f14iter + f14 = append(f14, &f14elem) + } + res.SetSecurityGroups(f14) + } + if cr.Spec.ForProvider.StorageType != nil { + res.SetStorageType(*cr.Spec.ForProvider.StorageType) + } + if cr.Spec.ForProvider.SubnetIDs != nil { + f16 := []*string{} + for _, f16iter := range cr.Spec.ForProvider.SubnetIDs { + var f16elem string + f16elem = *f16iter + f16 = append(f16, &f16elem) + } + res.SetSubnetIds(f16) + } + if cr.Spec.ForProvider.Tags != nil { + f17 := map[string]*string{} + for f17key, f17valiter := range cr.Spec.ForProvider.Tags { + var f17val string + f17val = *f17valiter + f17[f17key] = &f17val + } + res.SetTags(f17) + } + if cr.Spec.ForProvider.Users != nil { + f18 := []*svcsdk.User{} + for _, f18iter := range cr.Spec.ForProvider.Users { + f18elem := &svcsdk.User{} + if f18iter.ConsoleAccess != nil { + f18elem.SetConsoleAccess(*f18iter.ConsoleAccess) + } + if f18iter.Groups != nil { + f18elemf1 := []*string{} + for _, f18elemf1iter := range f18iter.Groups { + var f18elemf1elem string + f18elemf1elem = *f18elemf1iter + f18elemf1 = append(f18elemf1, &f18elemf1elem) + } + f18elem.SetGroups(f18elemf1) + } + if f18iter.Password != nil { + f18elem.SetPassword(*f18iter.Password) + } + if f18iter.Username != nil { + f18elem.SetUsername(*f18iter.Username) + } + f18 = append(f18, f18elem) + } + res.SetUsers(f18) + } + + return res +} + +// GenerateUpdateBrokerRequest returns an update input. +func GenerateUpdateBrokerRequest(cr *svcapitypes.Broker) *svcsdk.UpdateBrokerRequest { + res := &svcsdk.UpdateBrokerRequest{} + + if cr.Spec.ForProvider.AuthenticationStrategy != nil { + res.SetAuthenticationStrategy(*cr.Spec.ForProvider.AuthenticationStrategy) + } + if cr.Spec.ForProvider.AutoMinorVersionUpgrade != nil { + res.SetAutoMinorVersionUpgrade(*cr.Spec.ForProvider.AutoMinorVersionUpgrade) + } + if cr.Status.AtProvider.BrokerID != nil { + res.SetBrokerId(*cr.Status.AtProvider.BrokerID) + } + if cr.Spec.ForProvider.Configuration != nil { + f3 := &svcsdk.ConfigurationId{} + if cr.Spec.ForProvider.Configuration.ID != nil { + f3.SetId(*cr.Spec.ForProvider.Configuration.ID) + } + if cr.Spec.ForProvider.Configuration.Revision != nil { + f3.SetRevision(*cr.Spec.ForProvider.Configuration.Revision) + } + res.SetConfiguration(f3) + } + if cr.Spec.ForProvider.EngineVersion != nil { + res.SetEngineVersion(*cr.Spec.ForProvider.EngineVersion) + } + if cr.Spec.ForProvider.HostInstanceType != nil { + res.SetHostInstanceType(*cr.Spec.ForProvider.HostInstanceType) + } + if cr.Spec.ForProvider.LDAPServerMetadata != nil { + f6 := &svcsdk.LdapServerMetadataInput{} + if cr.Spec.ForProvider.LDAPServerMetadata.Hosts != nil { + f6f0 := []*string{} + for _, f6f0iter := range cr.Spec.ForProvider.LDAPServerMetadata.Hosts { + var f6f0elem string + f6f0elem = *f6f0iter + f6f0 = append(f6f0, &f6f0elem) + } + f6.SetHosts(f6f0) + } + if cr.Spec.ForProvider.LDAPServerMetadata.RoleBase != nil { + f6.SetRoleBase(*cr.Spec.ForProvider.LDAPServerMetadata.RoleBase) + } + if cr.Spec.ForProvider.LDAPServerMetadata.RoleName != nil { + f6.SetRoleName(*cr.Spec.ForProvider.LDAPServerMetadata.RoleName) + } + if cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchMatching != nil { + f6.SetRoleSearchMatching(*cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchMatching) + } + if cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchSubtree != nil { + f6.SetRoleSearchSubtree(*cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchSubtree) + } + if cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountPassword != nil { + f6.SetServiceAccountPassword(*cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountPassword) + } + if cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountUsername != nil { + f6.SetServiceAccountUsername(*cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountUsername) + } + if cr.Spec.ForProvider.LDAPServerMetadata.UserBase != nil { + f6.SetUserBase(*cr.Spec.ForProvider.LDAPServerMetadata.UserBase) + } + if cr.Spec.ForProvider.LDAPServerMetadata.UserRoleName != nil { + f6.SetUserRoleName(*cr.Spec.ForProvider.LDAPServerMetadata.UserRoleName) + } + if cr.Spec.ForProvider.LDAPServerMetadata.UserSearchMatching != nil { + f6.SetUserSearchMatching(*cr.Spec.ForProvider.LDAPServerMetadata.UserSearchMatching) + } + if cr.Spec.ForProvider.LDAPServerMetadata.UserSearchSubtree != nil { + f6.SetUserSearchSubtree(*cr.Spec.ForProvider.LDAPServerMetadata.UserSearchSubtree) + } + res.SetLdapServerMetadata(f6) + } + if cr.Spec.ForProvider.Logs != nil { + f7 := &svcsdk.Logs{} + if cr.Spec.ForProvider.Logs.Audit != nil { + f7.SetAudit(*cr.Spec.ForProvider.Logs.Audit) + } + if cr.Spec.ForProvider.Logs.General != nil { + f7.SetGeneral(*cr.Spec.ForProvider.Logs.General) + } + res.SetLogs(f7) + } + if cr.Spec.ForProvider.SecurityGroups != nil { + f8 := []*string{} + for _, f8iter := range cr.Spec.ForProvider.SecurityGroups { + var f8elem string + f8elem = *f8iter + f8 = append(f8, &f8elem) + } + res.SetSecurityGroups(f8) + } + + return res +} + +// GenerateDeleteBrokerInput returns a deletion input. +func GenerateDeleteBrokerInput(cr *svcapitypes.Broker) *svcsdk.DeleteBrokerInput { + res := &svcsdk.DeleteBrokerInput{} + + if cr.Status.AtProvider.BrokerID != nil { + res.SetBrokerId(*cr.Status.AtProvider.BrokerID) + } + + return res +} + +// IsNotFound returns whether the given error is of type NotFound or not. +func IsNotFound(err error) bool { + awsErr, ok := err.(awserr.Error) + return ok && awsErr.Code() == "NotFoundException" +} From 51bcfa19d60b0ac8ede61173a2cd8c2085549b8a Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Sat, 19 Jun 2021 09:40:03 -0700 Subject: [PATCH 02/10] feat(aws) : add references Signed-off-by: Praveen Ghuge --- apis/mq/v1alpha1/custom_type | 0 apis/mq/v1alpha1/custom_types.go | 15 ++++- apis/mq/v1alpha1/referencers.go | 47 +++++++++++++++ apis/mq/v1alpha1/zz_generated.deepcopy.go | 13 +++- examples/mq/broker.yaml | 9 +++ .../crds/mq.aws.crossplane.io_brokers.yaml | 24 ++++++++ pkg/controller/mq/broker/setup.go | 59 +++++++++++++++++-- 7 files changed, 159 insertions(+), 8 deletions(-) delete mode 100644 apis/mq/v1alpha1/custom_type create mode 100644 apis/mq/v1alpha1/referencers.go create mode 100644 examples/mq/broker.yaml diff --git a/apis/mq/v1alpha1/custom_type b/apis/mq/v1alpha1/custom_type deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/apis/mq/v1alpha1/custom_types.go b/apis/mq/v1alpha1/custom_types.go index 6477a6d72c..a0b56b2fd1 100644 --- a/apis/mq/v1alpha1/custom_types.go +++ b/apis/mq/v1alpha1/custom_types.go @@ -16,5 +16,18 @@ limitations under the License. package v1alpha1 +import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + // CustomBrokerParameters contains the additional fields for CustomBrokerParameters -type CustomBrokerParameters struct{} +type CustomBrokerParameters struct { + + // SubnetIDRefs is a list of references to Subnets used to set + // the SubnetIDs. + // +optional + SubnetIDRefs []xpv1.Reference `json:"subnetIDRefs,omitempty"` + + // SubnetIDsSelector selects references to Subnets used + // to set the SubnetIDs. + // +optional + SubnetIDSelector *xpv1.Selector `json:"subnetIDSelector,omitempty"` +} diff --git a/apis/mq/v1alpha1/referencers.go b/apis/mq/v1alpha1/referencers.go new file mode 100644 index 0000000000..ce71ad12d2 --- /dev/null +++ b/apis/mq/v1alpha1/referencers.go @@ -0,0 +1,47 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + "context" + + "github.com/crossplane/crossplane-runtime/pkg/reference" + ec2 "github.com/crossplane/provider-aws/apis/ec2/v1beta1" + "github.com/pkg/errors" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +// ResolveReferences of this Broker +func (mg *Broker) ResolveReferences(ctx context.Context, c client.Reader) error { + r := reference.NewAPIResolver(c, mg) + + // Resolve spec.forProvider.SubnetIds + mrsp, err := r.ResolveMultiple(ctx, reference.MultiResolutionRequest{ + CurrentValues: reference.FromPtrValues(mg.Spec.ForProvider.SubnetIDs), + References: mg.Spec.ForProvider.SubnetIDRefs, + Selector: mg.Spec.ForProvider.SubnetIDSelector, + To: reference.To{Managed: &ec2.Subnet{}, List: &ec2.SubnetList{}}, + Extract: reference.ExternalName(), + }) + if err != nil { + return errors.Wrap(err, "spec.forProvider.apiId") + } + mg.Spec.ForProvider.SubnetIDs = reference.ToPtrValues(mrsp.ResolvedValues) + mg.Spec.ForProvider.SubnetIDRefs = mrsp.ResolvedReferences + + return nil +} diff --git a/apis/mq/v1alpha1/zz_generated.deepcopy.go b/apis/mq/v1alpha1/zz_generated.deepcopy.go index 25a4579433..1dea9af245 100644 --- a/apis/mq/v1alpha1/zz_generated.deepcopy.go +++ b/apis/mq/v1alpha1/zz_generated.deepcopy.go @@ -21,6 +21,7 @@ limitations under the License. package v1alpha1 import ( + "github.com/crossplane/crossplane-runtime/apis/common/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -351,7 +352,7 @@ func (in *BrokerParameters) DeepCopyInto(out *BrokerParameters) { } } } - out.CustomBrokerParameters = in.CustomBrokerParameters + in.CustomBrokerParameters.DeepCopyInto(&out.CustomBrokerParameters) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerParameters. @@ -614,6 +615,16 @@ func (in *Configurations) DeepCopy() *Configurations { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CustomBrokerParameters) DeepCopyInto(out *CustomBrokerParameters) { *out = *in + if in.SubnetIDRefs != nil { + in, out := &in.SubnetIDRefs, &out.SubnetIDRefs + *out = make([]v1.Reference, len(*in)) + copy(*out, *in) + } + if in.SubnetIDSelector != nil { + in, out := &in.SubnetIDSelector, &out.SubnetIDSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomBrokerParameters. diff --git a/examples/mq/broker.yaml b/examples/mq/broker.yaml new file mode 100644 index 0000000000..5d9be3207e --- /dev/null +++ b/examples/mq/broker.yaml @@ -0,0 +1,9 @@ +apiVersion: mq.aws.crossplane.io/v1beta1 +kind: Broker +metadata: + name: example-mq +spec: + forProvider: + region: us-east-1 + providerConfigRef: + name: default diff --git a/package/crds/mq.aws.crossplane.io_brokers.yaml b/package/crds/mq.aws.crossplane.io_brokers.yaml index 5a14a16284..d5298777ce 100644 --- a/package/crds/mq.aws.crossplane.io_brokers.yaml +++ b/package/crds/mq.aws.crossplane.io_brokers.yaml @@ -139,6 +139,30 @@ spec: type: array storageType: type: string + subnetIDRefs: + description: SubnetIDRefs is a list of references to Subnets used to set the SubnetIDs. + items: + description: A Reference to a named object. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + type: array + subnetIDSelector: + description: SubnetIDsSelector selects references to Subnets used to set the SubnetIDs. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels is selected. + type: object + type: object subnetIDs: items: type: string diff --git a/pkg/controller/mq/broker/setup.go b/pkg/controller/mq/broker/setup.go index 086d0badcb..af0d6667a4 100644 --- a/pkg/controller/mq/broker/setup.go +++ b/pkg/controller/mq/broker/setup.go @@ -1,31 +1,78 @@ package broker import ( + "context" + "time" + "k8s.io/client-go/util/workqueue" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/controller" + svcsdk "github.com/aws/aws-sdk-go/service/mq" + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" "github.com/crossplane/crossplane-runtime/pkg/event" "github.com/crossplane/crossplane-runtime/pkg/logging" + "github.com/crossplane/crossplane-runtime/pkg/meta" "github.com/crossplane/crossplane-runtime/pkg/ratelimiter" "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" "github.com/crossplane/crossplane-runtime/pkg/resource" svcapitypes "github.com/crossplane/provider-aws/apis/mq/v1alpha1" + awsclients "github.com/crossplane/provider-aws/pkg/clients" ) -// SetupMQ adds a controller that reconciles Stage. -func SetupMQ(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error { - name := managed.ControllerName(svcapitypes.MQGroupKind) +// SetupBroker adds a controller that reconciles Stage. +func SetupBroker(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error { + name := managed.ControllerName(svcapitypes.BrokerKind) + opts := []option{ + func(e *external) { + e.postCreate = postCreate + e.preObserve = preObserve + e.preUpdate = preUpdate + e.preDelete = preDelete + e.postObserve = postObserve + }, + } return ctrl.NewControllerManagedBy(mgr). Named(name). WithOptions(controller.Options{ RateLimiter: ratelimiter.NewDefaultManagedRateLimiter(rl), }). - For(&svcapitypes.MQ{}). + For(&svcapitypes.Broker{}). Complete(managed.NewReconciler(mgr, - resource.ManagedKind(svcapitypes.MQGroupVersionKind), - managed.WithExternalConnecter(&connector{kube: mgr.GetClient()}), + resource.ManagedKind(svcapitypes.BrokerGroupVersionKind), + managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}), managed.WithLogger(l.WithValues("controller", name)), managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))))) } + +func preObserve(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.DescribeBrokerInput) error { + obj.BrokerId = awsclients.String(meta.GetExternalName(cr)) + return nil +} + +func postObserve(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.DescribeBrokerResponse, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) { + if err != nil { + return managed.ExternalObservation{}, err + } + cr.SetConditions(xpv1.Available()) + return obs, err +} + +func preUpdate(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.UpdateBrokerRequest) error { + obj.BrokerId = awsclients.String(meta.GetExternalName(cr)) + return nil +} + +func preDelete(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.DeleteBrokerInput) (bool, error) { + obj.BrokerId = awsclients.String(meta.GetExternalName(cr)) + return false, nil +} + +func postCreate(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.CreateBrokerResponse, cre managed.ExternalCreation, err error) (managed.ExternalCreation, error) { + if err != nil { + return managed.ExternalCreation{}, err + } + meta.SetExternalName(cr, awsclients.StringValue(obj.BrokerId)) + return managed.ExternalCreation{ExternalNameAssigned: true}, nil +} From d7e58a1baad78b37a98355ae8ac9a5615048dfff Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Sat, 19 Jun 2021 10:39:56 -0700 Subject: [PATCH 03/10] feat(aws): add example file Signed-off-by: Praveen Ghuge --- apis/mq/v1alpha1/referencers.go | 4 +++- examples/mq/broker.yaml | 9 --------- examples/mq/broker/broker.yaml | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 10 deletions(-) delete mode 100644 examples/mq/broker.yaml create mode 100644 examples/mq/broker/broker.yaml diff --git a/apis/mq/v1alpha1/referencers.go b/apis/mq/v1alpha1/referencers.go index ce71ad12d2..203597f6e3 100644 --- a/apis/mq/v1alpha1/referencers.go +++ b/apis/mq/v1alpha1/referencers.go @@ -20,9 +20,11 @@ import ( "context" "github.com/crossplane/crossplane-runtime/pkg/reference" - ec2 "github.com/crossplane/provider-aws/apis/ec2/v1beta1" + "github.com/pkg/errors" "sigs.k8s.io/controller-runtime/pkg/client" + + ec2 "github.com/crossplane/provider-aws/apis/ec2/v1beta1" ) // ResolveReferences of this Broker diff --git a/examples/mq/broker.yaml b/examples/mq/broker.yaml deleted file mode 100644 index 5d9be3207e..0000000000 --- a/examples/mq/broker.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: mq.aws.crossplane.io/v1beta1 -kind: Broker -metadata: - name: example-mq -spec: - forProvider: - region: us-east-1 - providerConfigRef: - name: default diff --git a/examples/mq/broker/broker.yaml b/examples/mq/broker/broker.yaml new file mode 100644 index 0000000000..db974bd7c8 --- /dev/null +++ b/examples/mq/broker/broker.yaml @@ -0,0 +1,15 @@ +apiVersion: mq.aws.crossplane.io/v1alpha1 +kind: Broker +metadata: + name: example-mq +spec: + forProvider: + region: us-east-1 + engineType: RabbitMQ + engineVersion: 3.8.11 + brokerName: example-mq + hostInstanceType: mq.t3.micro + deploymentMode: SINGLE_INSTANCE + subnetIDs: ["subnet-0ff63790fa036bec9"] + providerConfigRef: + name: default From 104924dc4548d4c2144158a26862c258e8b0d8f9 Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Sun, 20 Jun 2021 06:16:09 -0700 Subject: [PATCH 04/10] feat(aws): working yaml Signed-off-by: Praveen Ghuge --- examples/mq/broker/broker.yaml | 8 +++++++- pkg/controller/mq/broker/setup.go | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/examples/mq/broker/broker.yaml b/examples/mq/broker/broker.yaml index db974bd7c8..09ef0cbdfa 100644 --- a/examples/mq/broker/broker.yaml +++ b/examples/mq/broker/broker.yaml @@ -10,6 +10,12 @@ spec: brokerName: example-mq hostInstanceType: mq.t3.micro deploymentMode: SINGLE_INSTANCE - subnetIDs: ["subnet-0ff63790fa036bec9"] + subnetIDs: + - subnet-0e53acbc37671445c + securityGroups: + - sg-0308c28d22c7caf8b + users: + - password: ibmgsLab@123456 + username: praghuge providerConfigRef: name: default diff --git a/pkg/controller/mq/broker/setup.go b/pkg/controller/mq/broker/setup.go index af0d6667a4..ce800a736e 100644 --- a/pkg/controller/mq/broker/setup.go +++ b/pkg/controller/mq/broker/setup.go @@ -41,6 +41,7 @@ func SetupBroker(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, p For(&svcapitypes.Broker{}). Complete(managed.NewReconciler(mgr, resource.ManagedKind(svcapitypes.BrokerGroupVersionKind), + managed.WithInitializers(managed.NewDefaultProviderConfig(mgr.GetClient())), managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}), managed.WithLogger(l.WithValues("controller", name)), managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))))) @@ -55,7 +56,16 @@ func postObserve(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.Describe if err != nil { return managed.ExternalObservation{}, err } - cr.SetConditions(xpv1.Available()) + switch awsclients.StringValue(obj.BrokerState) { + case string(svcapitypes.BrokerState_RUNNING): + cr.SetConditions(xpv1.Available()) + case string(svcapitypes.BrokerState_CREATION_IN_PROGRESS): + cr.SetConditions(xpv1.Creating()) + case string(svcapitypes.BrokerState_REBOOT_IN_PROGRESS): + cr.SetConditions(xpv1.Unavailable()) + case string(svcapitypes.BrokerState_DELETION_IN_PROGRESS): + cr.SetConditions(xpv1.Deleting()) + } return obs, err } From 53e06338bb38977bcb51376fff12a1ac94be76dd Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Sun, 20 Jun 2021 07:44:06 -0700 Subject: [PATCH 05/10] feat(aws): add output params Signed-off-by: Praveen Ghuge --- apis/mq/v1alpha1/zz_broker.go | 4 +++- examples/mq/broker/broker.yaml | 6 +++--- package/crds/mq.aws.crossplane.io_brokers.yaml | 10 ++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/apis/mq/v1alpha1/zz_broker.go b/apis/mq/v1alpha1/zz_broker.go index f332165f58..3ef9b30e29 100644 --- a/apis/mq/v1alpha1/zz_broker.go +++ b/apis/mq/v1alpha1/zz_broker.go @@ -94,7 +94,9 @@ type BrokerStatus struct { // Broker is the Schema for the Brokers API // +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" // +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" -// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name" +// +kubebuilder:printcolumn:name="Broker engine",type="string",JSONPath=".spec.forProvider.engineType" +// +kubebuilder:printcolumn:name="Deployment mode",type="string",JSONPath=".spec.forProvider.deploymentMode" +// +kubebuilder:printcolumn:name="Instance type",type="string",JSONPath=".spec.forProvider.hostInstanceType" // +kubebuilder:subresource:status // +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,aws} type Broker struct { diff --git a/examples/mq/broker/broker.yaml b/examples/mq/broker/broker.yaml index 09ef0cbdfa..f80ddabb91 100644 --- a/examples/mq/broker/broker.yaml +++ b/examples/mq/broker/broker.yaml @@ -13,9 +13,9 @@ spec: subnetIDs: - subnet-0e53acbc37671445c securityGroups: - - sg-0308c28d22c7caf8b + - sg-0b3eceac4d82213f5 users: - - password: ibmgsLab@123456 - username: praghuge + - password: Password@123 + username: user123 providerConfigRef: name: default diff --git a/package/crds/mq.aws.crossplane.io_brokers.yaml b/package/crds/mq.aws.crossplane.io_brokers.yaml index d5298777ce..7e6e3d26bc 100644 --- a/package/crds/mq.aws.crossplane.io_brokers.yaml +++ b/package/crds/mq.aws.crossplane.io_brokers.yaml @@ -25,8 +25,14 @@ spec: - jsonPath: .status.conditions[?(@.type=='Synced')].status name: SYNCED type: string - - jsonPath: .metadata.annotations.crossplane\.io/external-name - name: EXTERNAL-NAME + - jsonPath: .spec.forProvider.engineType + name: Broker engine + type: string + - jsonPath: .spec.forProvider.deploymentMode + name: Deployment mode + type: string + - jsonPath: .spec.forProvider.hostInstanceType + name: Instance type type: string name: v1alpha1 schema: From 0a398cd88ce870875874a4f1577673d0ae3fea64 Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Tue, 29 Jun 2021 01:32:57 -0700 Subject: [PATCH 06/10] address changes related to formatting and securitygroup references Signed-off-by: Praveen Ghuge --- apis/mq/v1alpha1/custom_types.go | 10 +++++++ apis/mq/v1alpha1/referencers.go | 16 ++++++++++- apis/mq/v1alpha1/zz_broker.go | 1 + apis/mq/v1alpha1/zz_generated.deepcopy.go | 10 +++++++ examples/mq/broker/broker.yaml | 10 +++---- .../crds/mq.aws.crossplane.io_brokers.yaml | 27 +++++++++++++++++++ pkg/controller/aws.go | 1 + pkg/controller/mq/broker/setup.go | 6 ++++- 8 files changed, 74 insertions(+), 7 deletions(-) diff --git a/apis/mq/v1alpha1/custom_types.go b/apis/mq/v1alpha1/custom_types.go index a0b56b2fd1..f24de3af2e 100644 --- a/apis/mq/v1alpha1/custom_types.go +++ b/apis/mq/v1alpha1/custom_types.go @@ -30,4 +30,14 @@ type CustomBrokerParameters struct { // to set the SubnetIDs. // +optional SubnetIDSelector *xpv1.Selector `json:"subnetIDSelector,omitempty"` + + // SecurityGroupIDRefs is a list of references to SecurityGroups used to set + // the SecurityGroupsIDs. + // +optional + SecurityGroupIDRefs []xpv1.Reference `json:"securityGroupIdRefs,omitempty"` + + // SecurityGroupIDsSelector selects references to SecurityGroups used + // to set the SecurityGroupsIDs. + // +optional + SecurityGroupIDSelector *xpv1.Selector `json:"securityGroupIdSelector,omitempty"` } diff --git a/apis/mq/v1alpha1/referencers.go b/apis/mq/v1alpha1/referencers.go index 203597f6e3..f4ad1b8a68 100644 --- a/apis/mq/v1alpha1/referencers.go +++ b/apis/mq/v1alpha1/referencers.go @@ -40,10 +40,24 @@ func (mg *Broker) ResolveReferences(ctx context.Context, c client.Reader) error Extract: reference.ExternalName(), }) if err != nil { - return errors.Wrap(err, "spec.forProvider.apiId") + return errors.Wrap(err, "spec.forProvider.SubnetIDs") } mg.Spec.ForProvider.SubnetIDs = reference.ToPtrValues(mrsp.ResolvedValues) mg.Spec.ForProvider.SubnetIDRefs = mrsp.ResolvedReferences + // Resolve spec.forProvider.SecurityGroups + mrsp, err = r.ResolveMultiple(ctx, reference.MultiResolutionRequest{ + CurrentValues: reference.FromPtrValues(mg.Spec.ForProvider.SecurityGroups), + References: mg.Spec.ForProvider.SecurityGroupIDRefs, + Selector: mg.Spec.ForProvider.SecurityGroupIDSelector, + To: reference.To{Managed: &ec2.SecurityGroup{}, List: &ec2.SecurityGroupList{}}, + Extract: reference.ExternalName(), + }) + if err != nil { + return errors.Wrap(err, "spec.forProvider.SecurityGroups") + } + mg.Spec.ForProvider.SecurityGroups = reference.ToPtrValues(mrsp.ResolvedValues) + mg.Spec.ForProvider.SecurityGroupIDRefs = mrsp.ResolvedReferences + return nil } diff --git a/apis/mq/v1alpha1/zz_broker.go b/apis/mq/v1alpha1/zz_broker.go index 3ef9b30e29..1c7e873306 100644 --- a/apis/mq/v1alpha1/zz_broker.go +++ b/apis/mq/v1alpha1/zz_broker.go @@ -97,6 +97,7 @@ type BrokerStatus struct { // +kubebuilder:printcolumn:name="Broker engine",type="string",JSONPath=".spec.forProvider.engineType" // +kubebuilder:printcolumn:name="Deployment mode",type="string",JSONPath=".spec.forProvider.deploymentMode" // +kubebuilder:printcolumn:name="Instance type",type="string",JSONPath=".spec.forProvider.hostInstanceType" +// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name" // +kubebuilder:subresource:status // +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,aws} type Broker struct { diff --git a/apis/mq/v1alpha1/zz_generated.deepcopy.go b/apis/mq/v1alpha1/zz_generated.deepcopy.go index 1dea9af245..bce0bd0239 100644 --- a/apis/mq/v1alpha1/zz_generated.deepcopy.go +++ b/apis/mq/v1alpha1/zz_generated.deepcopy.go @@ -625,6 +625,16 @@ func (in *CustomBrokerParameters) DeepCopyInto(out *CustomBrokerParameters) { *out = new(v1.Selector) (*in).DeepCopyInto(*out) } + if in.SecurityGroupIDRefs != nil { + in, out := &in.SecurityGroupIDRefs, &out.SecurityGroupIDRefs + *out = make([]v1.Reference, len(*in)) + copy(*out, *in) + } + if in.SecurityGroupIDSelector != nil { + in, out := &in.SecurityGroupIDSelector, &out.SecurityGroupIDSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomBrokerParameters. diff --git a/examples/mq/broker/broker.yaml b/examples/mq/broker/broker.yaml index f80ddabb91..60bb32034e 100644 --- a/examples/mq/broker/broker.yaml +++ b/examples/mq/broker/broker.yaml @@ -10,12 +10,12 @@ spec: brokerName: example-mq hostInstanceType: mq.t3.micro deploymentMode: SINGLE_INSTANCE - subnetIDs: - - subnet-0e53acbc37671445c - securityGroups: - - sg-0b3eceac4d82213f5 + subnetIDRefs: + - name: sample-subnet1 + securityGroupIdRefs: + - name: sample-cluster-sg users: - password: Password@123 username: user123 providerConfigRef: - name: default + name: example diff --git a/package/crds/mq.aws.crossplane.io_brokers.yaml b/package/crds/mq.aws.crossplane.io_brokers.yaml index 7e6e3d26bc..491fc63c04 100644 --- a/package/crds/mq.aws.crossplane.io_brokers.yaml +++ b/package/crds/mq.aws.crossplane.io_brokers.yaml @@ -34,6 +34,9 @@ spec: - jsonPath: .spec.forProvider.hostInstanceType name: Instance type type: string + - jsonPath: .metadata.annotations.crossplane\.io/external-name + name: EXTERNAL-NAME + type: string name: v1alpha1 schema: openAPIV3Schema: @@ -139,6 +142,30 @@ spec: region: description: Region is which region the Broker will be created. type: string + securityGroupIdRefs: + description: SecurityGroupIDRefs is a list of references to SecurityGroups used to set the SecurityGroupsIDs. + items: + description: A Reference to a named object. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + type: array + securityGroupIdSelector: + description: SecurityGroupIDsSelector selects references to SecurityGroups used to set the SecurityGroupsIDs. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels is selected. + type: object + type: object securityGroups: items: type: string diff --git a/pkg/controller/aws.go b/pkg/controller/aws.go index 076b7aa4d8..0212ca665b 100644 --- a/pkg/controller/aws.go +++ b/pkg/controller/aws.go @@ -203,6 +203,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll ti resolverendpoint.SetupResolverEndpoint, resolverrule.SetupResolverRule, vpcpeeringconnection.SetupVPCPeeringConnection, + broker.SetupBroker, kafkacluster.SetupCluster, efsmounttarget.SetupMountTarget, transferserver.SetupServer, diff --git a/pkg/controller/mq/broker/setup.go b/pkg/controller/mq/broker/setup.go index ce800a736e..e0bb4a862f 100644 --- a/pkg/controller/mq/broker/setup.go +++ b/pkg/controller/mq/broker/setup.go @@ -65,6 +65,8 @@ func postObserve(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.Describe cr.SetConditions(xpv1.Unavailable()) case string(svcapitypes.BrokerState_DELETION_IN_PROGRESS): cr.SetConditions(xpv1.Deleting()) + case string(svcapitypes.BrokerState_CREATION_FAILED): + cr.SetConditions(xpv1.Unavailable()) } return obs, err } @@ -83,6 +85,8 @@ func postCreate(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.CreateBro if err != nil { return managed.ExternalCreation{}, err } + meta.SetExternalName(cr, awsclients.StringValue(obj.BrokerId)) - return managed.ExternalCreation{ExternalNameAssigned: true}, nil + cre.ExternalNameAssigned = true + return cre, nil } From 99b2de0e1ba75f9b15c03090ae77fe88d6aed2e5 Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Tue, 29 Jun 2021 11:28:48 -0700 Subject: [PATCH 07/10] add poll time to setup broker Signed-off-by: Praveen Ghuge --- pkg/controller/mq/broker/setup.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/controller/mq/broker/setup.go b/pkg/controller/mq/broker/setup.go index e0bb4a862f..633f3d096e 100644 --- a/pkg/controller/mq/broker/setup.go +++ b/pkg/controller/mq/broker/setup.go @@ -21,9 +21,9 @@ import ( awsclients "github.com/crossplane/provider-aws/pkg/clients" ) -// SetupBroker adds a controller that reconciles Stage. +// SetupBroker adds a controller that reconciles Broker. func SetupBroker(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error { - name := managed.ControllerName(svcapitypes.BrokerKind) + name := managed.ControllerName(svcapitypes.BrokerGroupKind) opts := []option{ func(e *external) { e.postCreate = postCreate From a3b3e9612d57a744627eccb1f5ef3463eb1ae4d6 Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Tue, 29 Jun 2021 11:42:30 -0700 Subject: [PATCH 08/10] add mq services to generated services list Signed-off-by: Praveen Ghuge --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6baddc3702..1c251921db 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ PROJECT_REPO := github.com/crossplane/$(PROJECT_NAME) PLATFORMS ?= linux_amd64 linux_arm64 CODE_GENERATOR_COMMIT ?= cac5654b7bb64c8f754ad9af01799ef70d9541b6 -GENERATED_SERVICES="apigatewayv2,cloudfront,dynamodb,efs,glue,kafka,kms,lambda,rds,secretsmanager,servicediscovery,sfn,transfer" +GENERATED_SERVICES="apigatewayv2,cloudfront,dynamodb,efs,glue,kafka,kms,lambda,mq,rds,secretsmanager,servicediscovery,sfn,transfer" # kind-related versions KIND_VERSION ?= v0.11.1 From 40196248604a00f9a651c80c8e2702f5fc0f9619 Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Wed, 30 Jun 2021 08:32:29 -0700 Subject: [PATCH 09/10] add poll interval Signed-off-by: Praveen Ghuge --- pkg/controller/mq/broker/setup.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/controller/mq/broker/setup.go b/pkg/controller/mq/broker/setup.go index 633f3d096e..f384b8a840 100644 --- a/pkg/controller/mq/broker/setup.go +++ b/pkg/controller/mq/broker/setup.go @@ -43,6 +43,7 @@ func SetupBroker(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, p resource.ManagedKind(svcapitypes.BrokerGroupVersionKind), managed.WithInitializers(managed.NewDefaultProviderConfig(mgr.GetClient())), managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}), + managed.WithPollInterval(poll), managed.WithLogger(l.WithValues("controller", name)), managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))))) } From 10bd27cc10827215ca4531e64c33ac1364c19583 Mon Sep 17 00:00:00 2001 From: haarchri Date: Tue, 9 Nov 2021 09:24:27 +0100 Subject: [PATCH 10/10] feat(mq): add user ressource & added passwordSecretRef for broker and user Signed-off-by: haarchri --- apis/mq/v1alpha1/custom_types.go | 29 ++ apis/mq/v1alpha1/generator-config.yaml | 7 +- apis/mq/v1alpha1/referencers.go | 21 ++ apis/mq/v1alpha1/zz_broker.go | 9 +- apis/mq/v1alpha1/zz_generated.deepcopy.go | 261 ++++++++++++++++-- apis/mq/v1alpha1/zz_generated.managed.go | 56 ++++ apis/mq/v1alpha1/zz_generated.managedlist.go | 9 + apis/mq/v1alpha1/zz_types.go | 18 +- apis/mq/v1alpha1/zz_user.go | 89 ++++++ examples/mq/activemq-broker.yaml | 37 +++ examples/mq/activemq-user.yaml | 29 ++ examples/mq/broker/broker.yaml | 21 -- examples/mq/rabbitmq-broker.yaml | 37 +++ .../crds/mq.aws.crossplane.io_brokers.yaml | 99 ++++--- package/crds/mq.aws.crossplane.io_users.yaml | 216 +++++++++++++++ pkg/clients/mq/mq.go | 70 +++++ pkg/clients/mq/mq_test.go | 242 ++++++++++++++++ pkg/controller/aws.go | 7 +- pkg/controller/mq/broker/setup.go | 60 +++- pkg/controller/mq/broker/zz_conversions.go | 135 ++++----- pkg/controller/mq/user/setup.go | 183 ++++++++++++ pkg/controller/mq/user/zz_controller.go | 220 +++++++++++++++ pkg/controller/mq/user/zz_conversions.go | 97 +++++++ 23 files changed, 1756 insertions(+), 196 deletions(-) create mode 100644 apis/mq/v1alpha1/zz_user.go create mode 100644 examples/mq/activemq-broker.yaml create mode 100644 examples/mq/activemq-user.yaml delete mode 100644 examples/mq/broker/broker.yaml create mode 100644 examples/mq/rabbitmq-broker.yaml create mode 100644 package/crds/mq.aws.crossplane.io_users.yaml create mode 100644 pkg/clients/mq/mq.go create mode 100644 pkg/clients/mq/mq_test.go create mode 100644 pkg/controller/mq/user/setup.go create mode 100644 pkg/controller/mq/user/zz_controller.go create mode 100644 pkg/controller/mq/user/zz_conversions.go diff --git a/apis/mq/v1alpha1/custom_types.go b/apis/mq/v1alpha1/custom_types.go index f24de3af2e..d169b269fd 100644 --- a/apis/mq/v1alpha1/custom_types.go +++ b/apis/mq/v1alpha1/custom_types.go @@ -40,4 +40,33 @@ type CustomBrokerParameters struct { // to set the SecurityGroupsIDs. // +optional SecurityGroupIDSelector *xpv1.Selector `json:"securityGroupIdSelector,omitempty"` + + CustomUsers []*CustomUser `json:"users,omitempty"` +} + +// CustomUser contains the fields for Users with PasswordSecretRef +type CustomUser struct { + ConsoleAccess *bool `json:"consoleAccess,omitempty"` + + Groups []*string `json:"groups,omitempty"` + + PasswordSecretRef xpv1.SecretKeySelector `json:"passwordSecretRef,omitempty"` + + Username *string `json:"username,omitempty"` +} + +// CustomUserParameters contains the additional fields for CustomUserParameters +type CustomUserParameters struct { + // +optional + BrokerID *string `json:"brokerID,omitempty"` + + // BrokerIDRef is a reference to a Broker used to set BrokerID. + // +optional + BrokerIDRef *xpv1.Reference `json:"brokerIDRef,omitempty"` + + // BrokerIDSelector selects a reference to a Broker used to set BrokerID. + // +optional + BrokerIDSelector *xpv1.Selector `json:"brokerIDSelector,omitempty"` + + PasswordSecretRef xpv1.SecretKeySelector `json:"passwordSecretRef,omitempty"` } diff --git a/apis/mq/v1alpha1/generator-config.yaml b/apis/mq/v1alpha1/generator-config.yaml index a4a22158ed..0d8b95d5a9 100644 --- a/apis/mq/v1alpha1/generator-config.yaml +++ b/apis/mq/v1alpha1/generator-config.yaml @@ -1,4 +1,9 @@ ignore: + field_paths: + - CreateBrokerRequest.Users + - CreateBrokerRequest.BrokerName + - CreateUserRequest.Username + - CreateUserRequest.BrokerId + - CreateUserRequest.Password resource_names: - Configuration - - User \ No newline at end of file diff --git a/apis/mq/v1alpha1/referencers.go b/apis/mq/v1alpha1/referencers.go index f4ad1b8a68..a3f4045bb1 100644 --- a/apis/mq/v1alpha1/referencers.go +++ b/apis/mq/v1alpha1/referencers.go @@ -61,3 +61,24 @@ func (mg *Broker) ResolveReferences(ctx context.Context, c client.Reader) error return nil } + +// ResolveReferences of this User +func (mg *User) ResolveReferences(ctx context.Context, c client.Reader) error { + r := reference.NewAPIResolver(c, mg) + + // Resolve spec.forProvider.brokerID + rsp, err := r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.BrokerID), + Reference: mg.Spec.ForProvider.BrokerIDRef, + Selector: mg.Spec.ForProvider.BrokerIDSelector, + To: reference.To{Managed: &Broker{}, List: &BrokerList{}}, + Extract: reference.ExternalName(), + }) + if err != nil { + return errors.Wrap(err, "spec.forProvider.brokerID") + } + mg.Spec.ForProvider.BrokerID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.BrokerIDRef = rsp.ResolvedReference + + return nil +} diff --git a/apis/mq/v1alpha1/zz_broker.go b/apis/mq/v1alpha1/zz_broker.go index 1c7e873306..bd455bf54c 100644 --- a/apis/mq/v1alpha1/zz_broker.go +++ b/apis/mq/v1alpha1/zz_broker.go @@ -34,8 +34,6 @@ type BrokerParameters struct { AutoMinorVersionUpgrade *bool `json:"autoMinorVersionUpgrade,omitempty"` - BrokerName *string `json:"brokerName,omitempty"` - Configuration *ConfigurationID `json:"configuration,omitempty"` CreatorRequestID *string `json:"creatorRequestID,omitempty"` @@ -64,9 +62,7 @@ type BrokerParameters struct { SubnetIDs []*string `json:"subnetIDs,omitempty"` - Tags map[string]*string `json:"tags,omitempty"` - - Users []*User `json:"users,omitempty"` + Tags map[string]*string `json:"tags,omitempty"` CustomBrokerParameters `json:",inline"` } @@ -94,9 +90,6 @@ type BrokerStatus struct { // Broker is the Schema for the Brokers API // +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" // +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" -// +kubebuilder:printcolumn:name="Broker engine",type="string",JSONPath=".spec.forProvider.engineType" -// +kubebuilder:printcolumn:name="Deployment mode",type="string",JSONPath=".spec.forProvider.deploymentMode" -// +kubebuilder:printcolumn:name="Instance type",type="string",JSONPath=".spec.forProvider.hostInstanceType" // +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name" // +kubebuilder:subresource:status // +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,aws} diff --git a/apis/mq/v1alpha1/zz_generated.deepcopy.go b/apis/mq/v1alpha1/zz_generated.deepcopy.go index bce0bd0239..b9332a5f6f 100644 --- a/apis/mq/v1alpha1/zz_generated.deepcopy.go +++ b/apis/mq/v1alpha1/zz_generated.deepcopy.go @@ -239,11 +239,6 @@ func (in *BrokerParameters) DeepCopyInto(out *BrokerParameters) { *out = new(bool) **out = **in } - if in.BrokerName != nil { - in, out := &in.BrokerName, &out.BrokerName - *out = new(string) - **out = **in - } if in.Configuration != nil { in, out := &in.Configuration, &out.Configuration *out = new(ConfigurationID) @@ -341,17 +336,6 @@ func (in *BrokerParameters) DeepCopyInto(out *BrokerParameters) { (*out)[key] = outVal } } - if in.Users != nil { - in, out := &in.Users, &out.Users - *out = make([]*User, len(*in)) - for i := range *in { - if (*in)[i] != nil { - in, out := &(*in)[i], &(*out)[i] - *out = new(User) - (*in).DeepCopyInto(*out) - } - } - } in.CustomBrokerParameters.DeepCopyInto(&out.CustomBrokerParameters) } @@ -635,6 +619,17 @@ func (in *CustomBrokerParameters) DeepCopyInto(out *CustomBrokerParameters) { *out = new(v1.Selector) (*in).DeepCopyInto(*out) } + if in.CustomUsers != nil { + in, out := &in.CustomUsers, &out.CustomUsers + *out = make([]*CustomUser, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(CustomUser) + (*in).DeepCopyInto(*out) + } + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomBrokerParameters. @@ -647,6 +642,74 @@ func (in *CustomBrokerParameters) DeepCopy() *CustomBrokerParameters { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CustomUser) DeepCopyInto(out *CustomUser) { + *out = *in + if in.ConsoleAccess != nil { + in, out := &in.ConsoleAccess, &out.ConsoleAccess + *out = new(bool) + **out = **in + } + if in.Groups != nil { + in, out := &in.Groups, &out.Groups + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } + out.PasswordSecretRef = in.PasswordSecretRef + if in.Username != nil { + in, out := &in.Username, &out.Username + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomUser. +func (in *CustomUser) DeepCopy() *CustomUser { + if in == nil { + return nil + } + out := new(CustomUser) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CustomUserParameters) DeepCopyInto(out *CustomUserParameters) { + *out = *in + if in.BrokerID != nil { + in, out := &in.BrokerID, &out.BrokerID + *out = new(string) + **out = **in + } + if in.BrokerIDRef != nil { + in, out := &in.BrokerIDRef, &out.BrokerIDRef + *out = new(v1.Reference) + **out = **in + } + if in.BrokerIDSelector != nil { + in, out := &in.BrokerIDSelector, &out.BrokerIDSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } + out.PasswordSecretRef = in.PasswordSecretRef +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomUserParameters. +func (in *CustomUserParameters) DeepCopy() *CustomUserParameters { + if in == nil { + return nil + } + out := new(CustomUserParameters) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EncryptionOptions) DeepCopyInto(out *EncryptionOptions) { *out = *in @@ -956,6 +1019,80 @@ func (in *SanitizationWarning) DeepCopy() *SanitizationWarning { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *User) DeepCopyInto(out *User) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new User. +func (in *User) DeepCopy() *User { + if in == nil { + return nil + } + out := new(User) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *User) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UserList) DeepCopyInto(out *UserList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]User, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserList. +func (in *UserList) DeepCopy() *UserList { + if in == nil { + return nil + } + out := new(UserList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *UserList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UserObservation) DeepCopyInto(out *UserObservation) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserObservation. +func (in *UserObservation) DeepCopy() *UserObservation { + if in == nil { + return nil + } + out := new(UserObservation) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UserParameters) DeepCopyInto(out *UserParameters) { *out = *in if in.ConsoleAccess != nil { in, out := &in.ConsoleAccess, &out.ConsoleAccess @@ -973,24 +1110,15 @@ func (in *User) DeepCopyInto(out *User) { } } } - if in.Password != nil { - in, out := &in.Password, &out.Password - *out = new(string) - **out = **in - } - if in.Username != nil { - in, out := &in.Username, &out.Username - *out = new(string) - **out = **in - } + in.CustomUserParameters.DeepCopyInto(&out.CustomUserParameters) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new User. -func (in *User) DeepCopy() *User { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserParameters. +func (in *UserParameters) DeepCopy() *UserParameters { if in == nil { return nil } - out := new(User) + out := new(UserParameters) in.DeepCopyInto(out) return out } @@ -1031,6 +1159,40 @@ func (in *UserPendingChanges) DeepCopy() *UserPendingChanges { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UserSpec) DeepCopyInto(out *UserSpec) { + *out = *in + in.ResourceSpec.DeepCopyInto(&out.ResourceSpec) + in.ForProvider.DeepCopyInto(&out.ForProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserSpec. +func (in *UserSpec) DeepCopy() *UserSpec { + if in == nil { + return nil + } + out := new(UserSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UserStatus) DeepCopyInto(out *UserStatus) { + *out = *in + in.ResourceStatus.DeepCopyInto(&out.ResourceStatus) + out.AtProvider = in.AtProvider +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserStatus. +func (in *UserStatus) DeepCopy() *UserStatus { + if in == nil { + return nil + } + out := new(UserStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *UserSummary) DeepCopyInto(out *UserSummary) { *out = *in @@ -1056,6 +1218,47 @@ func (in *UserSummary) DeepCopy() *UserSummary { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *User_SDK) DeepCopyInto(out *User_SDK) { + *out = *in + if in.ConsoleAccess != nil { + in, out := &in.ConsoleAccess, &out.ConsoleAccess + *out = new(bool) + **out = **in + } + if in.Groups != nil { + in, out := &in.Groups, &out.Groups + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } + if in.Password != nil { + in, out := &in.Password, &out.Password + *out = new(string) + **out = **in + } + if in.Username != nil { + in, out := &in.Username, &out.Username + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new User_SDK. +func (in *User_SDK) DeepCopy() *User_SDK { + if in == nil { + return nil + } + out := new(User_SDK) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WeeklyStartTime) DeepCopyInto(out *WeeklyStartTime) { *out = *in diff --git a/apis/mq/v1alpha1/zz_generated.managed.go b/apis/mq/v1alpha1/zz_generated.managed.go index d1c7b3687b..5940e15a05 100644 --- a/apis/mq/v1alpha1/zz_generated.managed.go +++ b/apis/mq/v1alpha1/zz_generated.managed.go @@ -75,3 +75,59 @@ func (mg *Broker) SetProviderReference(r *xpv1.Reference) { func (mg *Broker) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { mg.Spec.WriteConnectionSecretToReference = r } + +// GetCondition of this User. +func (mg *User) GetCondition(ct xpv1.ConditionType) xpv1.Condition { + return mg.Status.GetCondition(ct) +} + +// GetDeletionPolicy of this User. +func (mg *User) GetDeletionPolicy() xpv1.DeletionPolicy { + return mg.Spec.DeletionPolicy +} + +// GetProviderConfigReference of this User. +func (mg *User) GetProviderConfigReference() *xpv1.Reference { + return mg.Spec.ProviderConfigReference +} + +/* +GetProviderReference of this User. +Deprecated: Use GetProviderConfigReference. +*/ +func (mg *User) GetProviderReference() *xpv1.Reference { + return mg.Spec.ProviderReference +} + +// GetWriteConnectionSecretToReference of this User. +func (mg *User) GetWriteConnectionSecretToReference() *xpv1.SecretReference { + return mg.Spec.WriteConnectionSecretToReference +} + +// SetConditions of this User. +func (mg *User) SetConditions(c ...xpv1.Condition) { + mg.Status.SetConditions(c...) +} + +// SetDeletionPolicy of this User. +func (mg *User) SetDeletionPolicy(r xpv1.DeletionPolicy) { + mg.Spec.DeletionPolicy = r +} + +// SetProviderConfigReference of this User. +func (mg *User) SetProviderConfigReference(r *xpv1.Reference) { + mg.Spec.ProviderConfigReference = r +} + +/* +SetProviderReference of this User. +Deprecated: Use SetProviderConfigReference. +*/ +func (mg *User) SetProviderReference(r *xpv1.Reference) { + mg.Spec.ProviderReference = r +} + +// SetWriteConnectionSecretToReference of this User. +func (mg *User) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { + mg.Spec.WriteConnectionSecretToReference = r +} diff --git a/apis/mq/v1alpha1/zz_generated.managedlist.go b/apis/mq/v1alpha1/zz_generated.managedlist.go index 7bf7ad3364..13a237a66c 100644 --- a/apis/mq/v1alpha1/zz_generated.managedlist.go +++ b/apis/mq/v1alpha1/zz_generated.managedlist.go @@ -28,3 +28,12 @@ func (l *BrokerList) GetItems() []resource.Managed { } return items } + +// GetItems of this UserList. +func (l *UserList) GetItems() []resource.Managed { + items := make([]resource.Managed, len(l.Items)) + for i := range l.Items { + items[i] = &l.Items[i] + } + return items +} diff --git a/apis/mq/v1alpha1/zz_types.go b/apis/mq/v1alpha1/zz_types.go index 8617c0fdaf..ef612b77a1 100644 --- a/apis/mq/v1alpha1/zz_types.go +++ b/apis/mq/v1alpha1/zz_types.go @@ -209,27 +209,27 @@ type SanitizationWarning struct { ElementName *string `json:"elementName,omitempty"` } -type User struct { +type UserPendingChanges struct { ConsoleAccess *bool `json:"consoleAccess,omitempty"` Groups []*string `json:"groups,omitempty"` + // The type of change pending for the ActiveMQ user. + PendingChange *string `json:"pendingChange,omitempty"` +} - Password *string `json:"password,omitempty"` +type UserSummary struct { + // The type of change pending for the ActiveMQ user. + PendingChange *string `json:"pendingChange,omitempty"` Username *string `json:"username,omitempty"` } -type UserPendingChanges struct { +type User_SDK struct { ConsoleAccess *bool `json:"consoleAccess,omitempty"` Groups []*string `json:"groups,omitempty"` - // The type of change pending for the ActiveMQ user. - PendingChange *string `json:"pendingChange,omitempty"` -} -type UserSummary struct { - // The type of change pending for the ActiveMQ user. - PendingChange *string `json:"pendingChange,omitempty"` + Password *string `json:"password,omitempty"` Username *string `json:"username,omitempty"` } diff --git a/apis/mq/v1alpha1/zz_user.go b/apis/mq/v1alpha1/zz_user.go new file mode 100644 index 0000000000..fc084c8c09 --- /dev/null +++ b/apis/mq/v1alpha1/zz_user.go @@ -0,0 +1,89 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package v1alpha1 + +import ( + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// UserParameters defines the desired state of User +type UserParameters struct { + // Region is which region the User will be created. + // +kubebuilder:validation:Required + Region string `json:"region"` + + ConsoleAccess *bool `json:"consoleAccess,omitempty"` + + Groups []*string `json:"groups,omitempty"` + CustomUserParameters `json:",inline"` +} + +// UserSpec defines the desired state of User +type UserSpec struct { + xpv1.ResourceSpec `json:",inline"` + ForProvider UserParameters `json:"forProvider"` +} + +// UserObservation defines the observed state of User +type UserObservation struct { +} + +// UserStatus defines the observed state of User. +type UserStatus struct { + xpv1.ResourceStatus `json:",inline"` + AtProvider UserObservation `json:"atProvider,omitempty"` +} + +// +kubebuilder:object:root=true + +// User is the Schema for the Users API +// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" +// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" +// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name" +// +kubebuilder:subresource:status +// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,aws} +type User struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Spec UserSpec `json:"spec"` + Status UserStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// UserList contains a list of Users +type UserList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []User `json:"items"` +} + +// Repository type metadata. +var ( + UserKind = "User" + UserGroupKind = schema.GroupKind{Group: Group, Kind: UserKind}.String() + UserKindAPIVersion = UserKind + "." + GroupVersion.String() + UserGroupVersionKind = GroupVersion.WithKind(UserKind) +) + +func init() { + SchemeBuilder.Register(&User{}, &UserList{}) +} diff --git a/examples/mq/activemq-broker.yaml b/examples/mq/activemq-broker.yaml new file mode 100644 index 0000000000..a2d92b00ef --- /dev/null +++ b/examples/mq/activemq-broker.yaml @@ -0,0 +1,37 @@ +apiVersion: mq.aws.crossplane.io/v1alpha1 +kind: Broker +metadata: + name: example-activemq +spec: + forProvider: + region: eu-central-1 + engineType: ActiveMQ + storageType: EFS + engineVersion: 5.16.3 + hostInstanceType: mq.t3.micro + deploymentMode: SINGLE_INSTANCE + subnetIDRefs: + - name: sample-subnet1 + securityGroupIdRefs: + - name: sample-cluster-sg + users: + - username: activemq-admin + consoleAccess: true + passwordSecretRef: + key: password + name: example-activemq + namespace: crossplane-system + writeConnectionSecretToRef: + name: example-activemq + namespace: default + providerConfigRef: + name: default +--- +apiVersion: v1 +kind: Secret +metadata: + name: example-activemq + namespace: crossplane-system +type: Opaque +data: + password: dGVzdFBhc3N3b3JkITEyMw== # testPassword!123 diff --git a/examples/mq/activemq-user.yaml b/examples/mq/activemq-user.yaml new file mode 100644 index 0000000000..957d4af8fa --- /dev/null +++ b/examples/mq/activemq-user.yaml @@ -0,0 +1,29 @@ +# Note: The users API apply only ActiveMQ brokers. +# Making changes to a user does not apply the changes to the user immediately. +# To apply your changes, you must wait for the next maintenance window or reboot the broker. +# https://docs.aws.amazon.com/amazon-mq/latest/developer-guide/amazon-mq-broker-configuration-lifecycle.html +apiVersion: mq.aws.crossplane.io/v1alpha1 +kind: User +metadata: + name: example-activemq-user +spec: + forProvider: + region: eu-central-1 + brokerIDRef: + name: example-activemq + passwordSecretRef: + key: password + name: example-activemq-user + namespace: crossplane-system + writeConnectionSecretToRef: + name: example-activemq-user + namespace: default +--- +apiVersion: v1 +kind: Secret +metadata: + name: example-activemq-user + namespace: crossplane-system +type: Opaque +data: + password: dGVzdFBhc3N3b3JkITEyMw== # testPassword!123 \ No newline at end of file diff --git a/examples/mq/broker/broker.yaml b/examples/mq/broker/broker.yaml deleted file mode 100644 index 60bb32034e..0000000000 --- a/examples/mq/broker/broker.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: mq.aws.crossplane.io/v1alpha1 -kind: Broker -metadata: - name: example-mq -spec: - forProvider: - region: us-east-1 - engineType: RabbitMQ - engineVersion: 3.8.11 - brokerName: example-mq - hostInstanceType: mq.t3.micro - deploymentMode: SINGLE_INSTANCE - subnetIDRefs: - - name: sample-subnet1 - securityGroupIdRefs: - - name: sample-cluster-sg - users: - - password: Password@123 - username: user123 - providerConfigRef: - name: example diff --git a/examples/mq/rabbitmq-broker.yaml b/examples/mq/rabbitmq-broker.yaml new file mode 100644 index 0000000000..254ee92c6f --- /dev/null +++ b/examples/mq/rabbitmq-broker.yaml @@ -0,0 +1,37 @@ +apiVersion: mq.aws.crossplane.io/v1alpha1 +kind: Broker +metadata: + name: example-rabbitmq +spec: + forProvider: + region: eu-central-1 + engineType: RabbitMQ + engineVersion: 3.8.11 + hostInstanceType: mq.t3.micro + deploymentMode: SINGLE_INSTANCE + subnetIDRefs: + - name: sample-subnet1 + securityGroupIdRefs: + - name: sample-cluster-sg + users: + # To manage broker users, please use the RabbitMQ web console, or the management API + - username: rabbitmq-admin + consoleAccess: true + passwordSecretRef: + key: password + name: example-rabbitmq + namespace: crossplane-system + writeConnectionSecretToRef: + name: example-rabbitmq + namespace: default + providerConfigRef: + name: default +--- +apiVersion: v1 +kind: Secret +metadata: + name: example-rabbitmq + namespace: crossplane-system +type: Opaque +data: + password: dGVzdFBhc3N3b3JkITEyMw== # testPassword!123 diff --git a/package/crds/mq.aws.crossplane.io_brokers.yaml b/package/crds/mq.aws.crossplane.io_brokers.yaml index 491fc63c04..2218fab248 100644 --- a/package/crds/mq.aws.crossplane.io_brokers.yaml +++ b/package/crds/mq.aws.crossplane.io_brokers.yaml @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.4.0 + controller-gen.kubebuilder.io/version: v0.6.2 creationTimestamp: null name: brokers.mq.aws.crossplane.io spec: @@ -25,15 +25,6 @@ spec: - jsonPath: .status.conditions[?(@.type=='Synced')].status name: SYNCED type: string - - jsonPath: .spec.forProvider.engineType - name: Broker engine - type: string - - jsonPath: .spec.forProvider.deploymentMode - name: Deployment mode - type: string - - jsonPath: .spec.forProvider.hostInstanceType - name: Instance type - type: string - jsonPath: .metadata.annotations.crossplane\.io/external-name name: EXTERNAL-NAME type: string @@ -43,10 +34,14 @@ spec: description: Broker is the Schema for the Brokers API properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object @@ -55,7 +50,9 @@ spec: properties: deletionPolicy: default: Delete - description: DeletionPolicy specifies what will happen to the underlying external when this managed resource is deleted - either "Delete" or "Orphan" the external resource. + description: DeletionPolicy specifies what will happen to the underlying + external when this managed resource is deleted - either "Delete" + or "Orphan" the external resource. enum: - Orphan - Delete @@ -67,8 +64,6 @@ spec: type: string autoMinorVersionUpgrade: type: boolean - brokerName: - type: string configuration: properties: id: @@ -143,7 +138,8 @@ spec: description: Region is which region the Broker will be created. type: string securityGroupIdRefs: - description: SecurityGroupIDRefs is a list of references to SecurityGroups used to set the SecurityGroupsIDs. + description: SecurityGroupIDRefs is a list of references to SecurityGroups + used to set the SecurityGroupsIDs. items: description: A Reference to a named object. properties: @@ -155,15 +151,18 @@ spec: type: object type: array securityGroupIdSelector: - description: SecurityGroupIDsSelector selects references to SecurityGroups used to set the SecurityGroupsIDs. + description: SecurityGroupIDsSelector selects references to SecurityGroups + used to set the SecurityGroupsIDs. properties: matchControllerRef: - description: MatchControllerRef ensures an object with the same controller reference as the selecting object is selected. + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. type: boolean matchLabels: additionalProperties: type: string - description: MatchLabels ensures an object with matching labels is selected. + description: MatchLabels ensures an object with matching labels + is selected. type: object type: object securityGroups: @@ -173,7 +172,8 @@ spec: storageType: type: string subnetIDRefs: - description: SubnetIDRefs is a list of references to Subnets used to set the SubnetIDs. + description: SubnetIDRefs is a list of references to Subnets used + to set the SubnetIDs. items: description: A Reference to a named object. properties: @@ -185,15 +185,18 @@ spec: type: object type: array subnetIDSelector: - description: SubnetIDsSelector selects references to Subnets used to set the SubnetIDs. + description: SubnetIDsSelector selects references to Subnets used + to set the SubnetIDs. properties: matchControllerRef: - description: MatchControllerRef ensures an object with the same controller reference as the selecting object is selected. + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. type: boolean matchLabels: additionalProperties: type: string - description: MatchLabels ensures an object with matching labels is selected. + description: MatchLabels ensures an object with matching labels + is selected. type: object type: object subnetIDs: @@ -206,6 +209,7 @@ spec: type: object users: items: + description: CustomUser contains the fields for Users with PasswordSecretRef properties: consoleAccess: type: boolean @@ -213,8 +217,24 @@ spec: items: type: string type: array - password: - type: string + passwordSecretRef: + description: A SecretKeySelector is a reference to a secret + key in an arbitrary namespace. + properties: + key: + description: The key to select. + type: string + name: + description: Name of the secret. + type: string + namespace: + description: Namespace of the secret. + type: string + required: + - key + - name + - namespace + type: object username: type: string type: object @@ -225,7 +245,9 @@ spec: providerConfigRef: default: name: default - description: ProviderConfigReference specifies how the provider that will be used to create, observe, update, and delete this managed resource should be configured. + description: ProviderConfigReference specifies how the provider that + will be used to create, observe, update, and delete this managed + resource should be configured. properties: name: description: Name of the referenced object. @@ -234,7 +256,9 @@ spec: - name type: object providerRef: - description: 'ProviderReference specifies the provider that will be used to create, observe, update, and delete this managed resource. Deprecated: Please use ProviderConfigReference, i.e. `providerConfigRef`' + description: 'ProviderReference specifies the provider that will be + used to create, observe, update, and delete this managed resource. + Deprecated: Please use ProviderConfigReference, i.e. `providerConfigRef`' properties: name: description: Name of the referenced object. @@ -243,7 +267,11 @@ spec: - name type: object writeConnectionSecretToRef: - description: WriteConnectionSecretToReference specifies the namespace and name of a Secret to which any connection details for this managed resource should be written. Connection details frequently include the endpoint, username, and password required to connect to the managed resource. + description: WriteConnectionSecretToReference specifies the namespace + and name of a Secret to which any connection details for this managed + resource should be written. Connection details frequently include + the endpoint, username, and password required to connect to the + managed resource. properties: name: description: Name of the secret. @@ -275,20 +303,25 @@ spec: description: A Condition that may apply to a resource. properties: lastTransitionTime: - description: LastTransitionTime is the last time this condition transitioned from one status to another. + description: LastTransitionTime is the last time this condition + transitioned from one status to another. format: date-time type: string message: - description: A Message containing details about this condition's last transition from one status to another, if any. + description: A Message containing details about this condition's + last transition from one status to another, if any. type: string reason: - description: A Reason for this condition's last transition from one status to another. + description: A Reason for this condition's last transition from + one status to another. type: string status: - description: Status of this condition; is it currently True, False, or Unknown? + description: Status of this condition; is it currently True, + False, or Unknown? type: string type: - description: Type of this condition. At most one of each condition type may apply to a resource at any point in time. + description: Type of this condition. At most one of each condition + type may apply to a resource at any point in time. type: string required: - lastTransitionTime diff --git a/package/crds/mq.aws.crossplane.io_users.yaml b/package/crds/mq.aws.crossplane.io_users.yaml new file mode 100644 index 0000000000..93b6029a90 --- /dev/null +++ b/package/crds/mq.aws.crossplane.io_users.yaml @@ -0,0 +1,216 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.6.2 + creationTimestamp: null + name: users.mq.aws.crossplane.io +spec: + group: mq.aws.crossplane.io + names: + categories: + - crossplane + - managed + - aws + kind: User + listKind: UserList + plural: users + singular: user + scope: Cluster + versions: + - additionalPrinterColumns: + - jsonPath: .status.conditions[?(@.type=='Ready')].status + name: READY + type: string + - jsonPath: .status.conditions[?(@.type=='Synced')].status + name: SYNCED + type: string + - jsonPath: .metadata.annotations.crossplane\.io/external-name + name: EXTERNAL-NAME + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: User is the Schema for the Users API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: UserSpec defines the desired state of User + properties: + deletionPolicy: + default: Delete + description: DeletionPolicy specifies what will happen to the underlying + external when this managed resource is deleted - either "Delete" + or "Orphan" the external resource. + enum: + - Orphan + - Delete + type: string + forProvider: + description: UserParameters defines the desired state of User + properties: + brokerID: + type: string + brokerIDRef: + description: BrokerIDRef is a reference to a Broker used to set + BrokerID. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + brokerIDSelector: + description: BrokerIDSelector selects a reference to a Broker + used to set BrokerID. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + type: object + consoleAccess: + type: boolean + groups: + items: + type: string + type: array + passwordSecretRef: + description: A SecretKeySelector is a reference to a secret key + in an arbitrary namespace. + properties: + key: + description: The key to select. + type: string + name: + description: Name of the secret. + type: string + namespace: + description: Namespace of the secret. + type: string + required: + - key + - name + - namespace + type: object + region: + description: Region is which region the User will be created. + type: string + required: + - region + type: object + providerConfigRef: + default: + name: default + description: ProviderConfigReference specifies how the provider that + will be used to create, observe, update, and delete this managed + resource should be configured. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + providerRef: + description: 'ProviderReference specifies the provider that will be + used to create, observe, update, and delete this managed resource. + Deprecated: Please use ProviderConfigReference, i.e. `providerConfigRef`' + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + writeConnectionSecretToRef: + description: WriteConnectionSecretToReference specifies the namespace + and name of a Secret to which any connection details for this managed + resource should be written. Connection details frequently include + the endpoint, username, and password required to connect to the + managed resource. + properties: + name: + description: Name of the secret. + type: string + namespace: + description: Namespace of the secret. + type: string + required: + - name + - namespace + type: object + required: + - forProvider + type: object + status: + description: UserStatus defines the observed state of User. + properties: + atProvider: + description: UserObservation defines the observed state of User + type: object + conditions: + description: Conditions of the resource. + items: + description: A Condition that may apply to a resource. + properties: + lastTransitionTime: + description: LastTransitionTime is the last time this condition + transitioned from one status to another. + format: date-time + type: string + message: + description: A Message containing details about this condition's + last transition from one status to another, if any. + type: string + reason: + description: A Reason for this condition's last transition from + one status to another. + type: string + status: + description: Status of this condition; is it currently True, + False, or Unknown? + type: string + type: + description: Type of this condition. At most one of each condition + type may apply to a resource at any point in time. + type: string + required: + - lastTransitionTime + - reason + - status + - type + type: object + type: array + type: object + required: + - spec + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/pkg/clients/mq/mq.go b/pkg/clients/mq/mq.go new file mode 100644 index 0000000000..334a8037b1 --- /dev/null +++ b/pkg/clients/mq/mq.go @@ -0,0 +1,70 @@ +/* +Copyright 2019 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package mq + +import ( + "context" + + "github.com/pkg/errors" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" + + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + "github.com/crossplane/crossplane-runtime/pkg/resource" +) + +const ( + errGetPasswordSecretFailed = "cannot get password secret" +) + +// Client defines MQ MQClient operations +type Client interface{} + +// GetPassword fetches the referenced input password for an MQBroker CRD and determines whether it has changed or not +func GetPassword(ctx context.Context, kube client.Client, in *xpv1.SecretKeySelector, out *xpv1.SecretReference) (newPwd string, changed bool, err error) { + if in == nil { + return "", false, nil + } + nn := types.NamespacedName{ + Name: in.Name, + Namespace: in.Namespace, + } + s := &corev1.Secret{} + if err := kube.Get(ctx, nn, s); err != nil { + return "", false, errors.Wrap(err, errGetPasswordSecretFailed) + } + newPwd = string(s.Data[in.Key]) + + if out != nil { + nn = types.NamespacedName{ + Name: out.Name, + Namespace: out.Namespace, + } + s = &corev1.Secret{} + // the output secret may not exist yet, so we can skip returning an + // error if the error is NotFound + if err := kube.Get(ctx, nn, s); resource.IgnoreNotFound(err) != nil { + return "", false, err + } + // if newPwd was set to some value, compare value in output secret with + // newPwd + changed = newPwd != "" && newPwd != string(s.Data[xpv1.ResourceCredentialsSecretPasswordKey]) + } + + return newPwd, changed, nil +} diff --git a/pkg/clients/mq/mq_test.go b/pkg/clients/mq/mq_test.go new file mode 100644 index 0000000000..9e8afc98d3 --- /dev/null +++ b/pkg/clients/mq/mq_test.go @@ -0,0 +1,242 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package mq + +import ( + "context" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/pkg/errors" + corev1 "k8s.io/api/core/v1" + kerrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/client" + + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + "github.com/crossplane/crossplane-runtime/pkg/test" +) + +var ( + secretNamespace = "crossplane-system" + connectionSecretName = "my-little-secret" + connectionSecretKey = "credentials" + connectionCredData = "confidential!" + outputSecretName = "my-saved-secret" + + errBoom = errors.New("boom") +) + +func TestGetPassword(t *testing.T) { + type args struct { + in *xpv1.SecretKeySelector + out *xpv1.SecretReference + kube client.Client + } + type want struct { + Pwd string + Changed bool + Err error + } + + cases := map[string]struct { + args args + want want + }{ + "SamePassword": { + args: args{ + in: &xpv1.SecretKeySelector{ + SecretReference: xpv1.SecretReference{ + Name: connectionSecretName, + Namespace: secretNamespace, + }, + Key: connectionSecretKey, + }, + out: &xpv1.SecretReference{ + Name: outputSecretName, + Namespace: secretNamespace, + }, + kube: &test.MockClient{ + MockGet: func(_ context.Context, key client.ObjectKey, obj client.Object) error { + switch key.Name { + case connectionSecretName: + secret := corev1.Secret{ + Data: map[string][]byte{}, + } + secret.Data[connectionSecretKey] = []byte(connectionCredData) + secret.DeepCopyInto(obj.(*corev1.Secret)) + return nil + case outputSecretName: + secret := corev1.Secret{ + Data: map[string][]byte{}, + } + secret.Data[xpv1.ResourceCredentialsSecretPasswordKey] = []byte(connectionCredData) + secret.DeepCopyInto(obj.(*corev1.Secret)) + return nil + default: + return nil + } + }, + }, + }, + want: want{ + Pwd: connectionCredData, + Changed: false, + Err: nil, + }, + }, + "DifferentPassword": { + args: args{ + in: &xpv1.SecretKeySelector{ + SecretReference: xpv1.SecretReference{ + Name: connectionSecretName, + Namespace: secretNamespace, + }, + Key: connectionSecretKey, + }, + out: &xpv1.SecretReference{ + Name: outputSecretName, + Namespace: secretNamespace, + }, + kube: &test.MockClient{ + MockGet: func(_ context.Context, key client.ObjectKey, obj client.Object) error { + switch key.Name { + case connectionSecretName: + secret := corev1.Secret{ + Data: map[string][]byte{}, + } + secret.Data[connectionSecretKey] = []byte(connectionCredData) + secret.DeepCopyInto(obj.(*corev1.Secret)) + return nil + case outputSecretName: + secret := corev1.Secret{ + Data: map[string][]byte{}, + } + secret.Data[xpv1.ResourceCredentialsSecretPasswordKey] = []byte("not" + connectionCredData) + secret.DeepCopyInto(obj.(*corev1.Secret)) + return nil + default: + return nil + } + }, + }, + }, + want: want{ + Pwd: connectionCredData, + Changed: true, + Err: nil, + }, + }, + "ErrorOnInput": { + args: args{ + in: &xpv1.SecretKeySelector{ + SecretReference: xpv1.SecretReference{ + Name: connectionSecretName, + Namespace: secretNamespace, + }, + Key: connectionSecretKey, + }, + kube: &test.MockClient{ + MockGet: func(_ context.Context, key client.ObjectKey, obj client.Object) error { + return errBoom + }, + }, + }, + want: want{ + Pwd: "", + Changed: false, + Err: errors.Wrap(errBoom, errGetPasswordSecretFailed), + }, + }, + "OutputDoesNotExistYet": { + args: args{ + in: &xpv1.SecretKeySelector{ + SecretReference: xpv1.SecretReference{ + Name: connectionSecretName, + Namespace: secretNamespace, + }, + Key: connectionSecretKey, + }, + out: &xpv1.SecretReference{ + Name: outputSecretName, + Namespace: secretNamespace, + }, + kube: &test.MockClient{ + MockGet: func(_ context.Context, key client.ObjectKey, obj client.Object) error { + switch key.Name { + case connectionSecretName: + secret := corev1.Secret{ + Data: map[string][]byte{}, + } + secret.Data[connectionSecretKey] = []byte(connectionCredData) + secret.DeepCopyInto(obj.(*corev1.Secret)) + return nil + case outputSecretName: + return kerrors.NewNotFound(schema.GroupResource{ + Resource: "Secret", + }, outputSecretName) + default: + return nil + } + }, + }, + }, + want: want{ + Pwd: connectionCredData, + Changed: true, + Err: nil, + }, + }, + + "NoInputPassword": { + args: args{ + out: &xpv1.SecretReference{ + Name: outputSecretName, + Namespace: secretNamespace, + }, + kube: &test.MockClient{ + MockGet: func(_ context.Context, key client.ObjectKey, obj client.Object) error { + secret := corev1.Secret{ + Data: map[string][]byte{}, + } + secret.Data[xpv1.ResourceCredentialsSecretPasswordKey] = []byte("not" + connectionCredData) + secret.DeepCopyInto(obj.(*corev1.Secret)) + return nil + }, + }, + }, + want: want{ + Pwd: "", + Changed: false, + Err: nil, + }, + }, + } + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + ctx := context.Background() + pwd, changed, err := GetPassword(ctx, tc.args.kube, tc.args.in, tc.args.out) + if diff := cmp.Diff(tc.want, want{ + Pwd: pwd, + Changed: changed, + Err: err, + }, test.EquateErrors()); diff != "" { + t.Errorf("r: -want, +got:\n%s", diff) + } + }) + } +} diff --git a/pkg/controller/aws.go b/pkg/controller/aws.go index 0212ca665b..4373062c37 100644 --- a/pkg/controller/aws.go +++ b/pkg/controller/aws.go @@ -93,7 +93,8 @@ import ( kafkacluster "github.com/crossplane/provider-aws/pkg/controller/kafka/cluster" "github.com/crossplane/provider-aws/pkg/controller/kms/key" "github.com/crossplane/provider-aws/pkg/controller/lambda/function" - "github.com/crossplane/provider-aws/pkg/controller/mq/broker" + mqbroker "github.com/crossplane/provider-aws/pkg/controller/mq/broker" + mquser "github.com/crossplane/provider-aws/pkg/controller/mq/user" "github.com/crossplane/provider-aws/pkg/controller/notification/snssubscription" "github.com/crossplane/provider-aws/pkg/controller/notification/snstopic" "github.com/crossplane/provider-aws/pkg/controller/rds/dbcluster" @@ -203,7 +204,6 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll ti resolverendpoint.SetupResolverEndpoint, resolverrule.SetupResolverRule, vpcpeeringconnection.SetupVPCPeeringConnection, - broker.SetupBroker, kafkacluster.SetupCluster, efsmounttarget.SetupMountTarget, transferserver.SetupServer, @@ -215,7 +215,8 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll ti glueDatabase.SetupDatabase, gluecrawler.SetupCrawler, glueclassifier.SetupClassifier, - broker.SetupBroker, + mqbroker.SetupBroker, + mquser.SetupUser, } { if err := setup(mgr, l, rl, poll); err != nil { return err diff --git a/pkg/controller/mq/broker/setup.go b/pkg/controller/mq/broker/setup.go index f384b8a840..d471e21916 100644 --- a/pkg/controller/mq/broker/setup.go +++ b/pkg/controller/mq/broker/setup.go @@ -6,9 +6,11 @@ import ( "k8s.io/client-go/util/workqueue" ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" svcsdk "github.com/aws/aws-sdk-go/service/mq" + svcsdkapi "github.com/aws/aws-sdk-go/service/mq/mqiface" xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" "github.com/crossplane/crossplane-runtime/pkg/event" "github.com/crossplane/crossplane-runtime/pkg/logging" @@ -16,9 +18,11 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/ratelimiter" "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" "github.com/crossplane/crossplane-runtime/pkg/resource" + "github.com/pkg/errors" svcapitypes "github.com/crossplane/provider-aws/apis/mq/v1alpha1" awsclients "github.com/crossplane/provider-aws/pkg/clients" + "github.com/crossplane/provider-aws/pkg/clients/mq" ) // SetupBroker adds a controller that reconciles Broker. @@ -26,17 +30,18 @@ func SetupBroker(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, p name := managed.ControllerName(svcapitypes.BrokerGroupKind) opts := []option{ func(e *external) { + c := &custom{client: e.client, kube: e.kube, external: e} + e.preCreate = c.preCreate e.postCreate = postCreate e.preObserve = preObserve - e.preUpdate = preUpdate e.preDelete = preDelete - e.postObserve = postObserve + e.postObserve = c.postObserve }, } return ctrl.NewControllerManagedBy(mgr). Named(name). WithOptions(controller.Options{ - RateLimiter: ratelimiter.NewDefaultManagedRateLimiter(rl), + RateLimiter: ratelimiter.NewController(rl), }). For(&svcapitypes.Broker{}). Complete(managed.NewReconciler(mgr, @@ -48,12 +53,18 @@ func SetupBroker(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, p managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))))) } +type custom struct { + kube client.Client + client svcsdkapi.MQAPI + external *external +} + func preObserve(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.DescribeBrokerInput) error { obj.BrokerId = awsclients.String(meta.GetExternalName(cr)) return nil } -func postObserve(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.DescribeBrokerResponse, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) { +func (e *custom) postObserve(ctx context.Context, cr *svcapitypes.Broker, obj *svcsdk.DescribeBrokerResponse, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) { if err != nil { return managed.ExternalObservation{}, err } @@ -69,12 +80,21 @@ func postObserve(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.Describe case string(svcapitypes.BrokerState_CREATION_FAILED): cr.SetConditions(xpv1.Unavailable()) } - return obs, err -} -func preUpdate(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.UpdateBrokerRequest) error { - obj.BrokerId = awsclients.String(meta.GetExternalName(cr)) - return nil + pw, _, err := mq.GetPassword(ctx, e.kube, &cr.Spec.ForProvider.CustomUsers[0].PasswordSecretRef, cr.Spec.WriteConnectionSecretToReference) + if resource.IgnoreNotFound(err) != nil || pw == "" { + return obs, errors.Wrap(err, "cannot get password from the given secret") + } + + obs.ConnectionDetails = managed.ConnectionDetails{ + "BrokerID": []byte(awsclients.StringValue(cr.Status.AtProvider.BrokerID)), + "Region": []byte(awsclients.StringValue(&cr.Spec.ForProvider.Region)), + "Username": []byte(awsclients.StringValue(cr.Spec.ForProvider.CustomUsers[0].Username)), + "Password": []byte(pw), + } + + return obs, nil + } func preDelete(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.DeleteBrokerInput) (bool, error) { @@ -82,12 +102,32 @@ func preDelete(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.DeleteBrok return false, nil } +func (e *custom) preCreate(ctx context.Context, cr *svcapitypes.Broker, obj *svcsdk.CreateBrokerRequest) error { + + obj.BrokerName = awsclients.String(cr.Name) + + pw, _, err := mq.GetPassword(ctx, e.kube, &cr.Spec.ForProvider.CustomUsers[0].PasswordSecretRef, cr.Spec.WriteConnectionSecretToReference) + if resource.IgnoreNotFound(err) != nil || pw == "" { + return errors.Wrap(err, "cannot get password from the given secret") + } + + obj.Users = []*svcsdk.User{ + { + Username: cr.Spec.ForProvider.CustomUsers[0].Username, + Password: awsclients.String(pw), + ConsoleAccess: cr.Spec.ForProvider.CustomUsers[0].ConsoleAccess, + Groups: cr.Spec.ForProvider.CustomUsers[0].Groups, + }, + } + + return nil +} + func postCreate(_ context.Context, cr *svcapitypes.Broker, obj *svcsdk.CreateBrokerResponse, cre managed.ExternalCreation, err error) (managed.ExternalCreation, error) { if err != nil { return managed.ExternalCreation{}, err } meta.SetExternalName(cr, awsclients.StringValue(obj.BrokerId)) - cre.ExternalNameAssigned = true return cre, nil } diff --git a/pkg/controller/mq/broker/zz_conversions.go b/pkg/controller/mq/broker/zz_conversions.go index d61c8439fd..2322c94977 100644 --- a/pkg/controller/mq/broker/zz_conversions.go +++ b/pkg/controller/mq/broker/zz_conversions.go @@ -68,18 +68,15 @@ func GenerateCreateBrokerRequest(cr *svcapitypes.Broker) *svcsdk.CreateBrokerReq if cr.Spec.ForProvider.AutoMinorVersionUpgrade != nil { res.SetAutoMinorVersionUpgrade(*cr.Spec.ForProvider.AutoMinorVersionUpgrade) } - if cr.Spec.ForProvider.BrokerName != nil { - res.SetBrokerName(*cr.Spec.ForProvider.BrokerName) - } if cr.Spec.ForProvider.Configuration != nil { - f3 := &svcsdk.ConfigurationId{} + f2 := &svcsdk.ConfigurationId{} if cr.Spec.ForProvider.Configuration.ID != nil { - f3.SetId(*cr.Spec.ForProvider.Configuration.ID) + f2.SetId(*cr.Spec.ForProvider.Configuration.ID) } if cr.Spec.ForProvider.Configuration.Revision != nil { - f3.SetRevision(*cr.Spec.ForProvider.Configuration.Revision) + f2.SetRevision(*cr.Spec.ForProvider.Configuration.Revision) } - res.SetConfiguration(f3) + res.SetConfiguration(f2) } if cr.Spec.ForProvider.CreatorRequestID != nil { res.SetCreatorRequestId(*cr.Spec.ForProvider.CreatorRequestID) @@ -88,14 +85,14 @@ func GenerateCreateBrokerRequest(cr *svcapitypes.Broker) *svcsdk.CreateBrokerReq res.SetDeploymentMode(*cr.Spec.ForProvider.DeploymentMode) } if cr.Spec.ForProvider.EncryptionOptions != nil { - f6 := &svcsdk.EncryptionOptions{} + f5 := &svcsdk.EncryptionOptions{} if cr.Spec.ForProvider.EncryptionOptions.KMSKeyID != nil { - f6.SetKmsKeyId(*cr.Spec.ForProvider.EncryptionOptions.KMSKeyID) + f5.SetKmsKeyId(*cr.Spec.ForProvider.EncryptionOptions.KMSKeyID) } if cr.Spec.ForProvider.EncryptionOptions.UseAWSOwnedKey != nil { - f6.SetUseAwsOwnedKey(*cr.Spec.ForProvider.EncryptionOptions.UseAWSOwnedKey) + f5.SetUseAwsOwnedKey(*cr.Spec.ForProvider.EncryptionOptions.UseAWSOwnedKey) } - res.SetEncryptionOptions(f6) + res.SetEncryptionOptions(f5) } if cr.Spec.ForProvider.EngineType != nil { res.SetEngineType(*cr.Spec.ForProvider.EngineType) @@ -107,129 +104,103 @@ func GenerateCreateBrokerRequest(cr *svcapitypes.Broker) *svcsdk.CreateBrokerReq res.SetHostInstanceType(*cr.Spec.ForProvider.HostInstanceType) } if cr.Spec.ForProvider.LDAPServerMetadata != nil { - f10 := &svcsdk.LdapServerMetadataInput{} + f9 := &svcsdk.LdapServerMetadataInput{} if cr.Spec.ForProvider.LDAPServerMetadata.Hosts != nil { - f10f0 := []*string{} - for _, f10f0iter := range cr.Spec.ForProvider.LDAPServerMetadata.Hosts { - var f10f0elem string - f10f0elem = *f10f0iter - f10f0 = append(f10f0, &f10f0elem) + f9f0 := []*string{} + for _, f9f0iter := range cr.Spec.ForProvider.LDAPServerMetadata.Hosts { + var f9f0elem string + f9f0elem = *f9f0iter + f9f0 = append(f9f0, &f9f0elem) } - f10.SetHosts(f10f0) + f9.SetHosts(f9f0) } if cr.Spec.ForProvider.LDAPServerMetadata.RoleBase != nil { - f10.SetRoleBase(*cr.Spec.ForProvider.LDAPServerMetadata.RoleBase) + f9.SetRoleBase(*cr.Spec.ForProvider.LDAPServerMetadata.RoleBase) } if cr.Spec.ForProvider.LDAPServerMetadata.RoleName != nil { - f10.SetRoleName(*cr.Spec.ForProvider.LDAPServerMetadata.RoleName) + f9.SetRoleName(*cr.Spec.ForProvider.LDAPServerMetadata.RoleName) } if cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchMatching != nil { - f10.SetRoleSearchMatching(*cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchMatching) + f9.SetRoleSearchMatching(*cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchMatching) } if cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchSubtree != nil { - f10.SetRoleSearchSubtree(*cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchSubtree) + f9.SetRoleSearchSubtree(*cr.Spec.ForProvider.LDAPServerMetadata.RoleSearchSubtree) } if cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountPassword != nil { - f10.SetServiceAccountPassword(*cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountPassword) + f9.SetServiceAccountPassword(*cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountPassword) } if cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountUsername != nil { - f10.SetServiceAccountUsername(*cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountUsername) + f9.SetServiceAccountUsername(*cr.Spec.ForProvider.LDAPServerMetadata.ServiceAccountUsername) } if cr.Spec.ForProvider.LDAPServerMetadata.UserBase != nil { - f10.SetUserBase(*cr.Spec.ForProvider.LDAPServerMetadata.UserBase) + f9.SetUserBase(*cr.Spec.ForProvider.LDAPServerMetadata.UserBase) } if cr.Spec.ForProvider.LDAPServerMetadata.UserRoleName != nil { - f10.SetUserRoleName(*cr.Spec.ForProvider.LDAPServerMetadata.UserRoleName) + f9.SetUserRoleName(*cr.Spec.ForProvider.LDAPServerMetadata.UserRoleName) } if cr.Spec.ForProvider.LDAPServerMetadata.UserSearchMatching != nil { - f10.SetUserSearchMatching(*cr.Spec.ForProvider.LDAPServerMetadata.UserSearchMatching) + f9.SetUserSearchMatching(*cr.Spec.ForProvider.LDAPServerMetadata.UserSearchMatching) } if cr.Spec.ForProvider.LDAPServerMetadata.UserSearchSubtree != nil { - f10.SetUserSearchSubtree(*cr.Spec.ForProvider.LDAPServerMetadata.UserSearchSubtree) + f9.SetUserSearchSubtree(*cr.Spec.ForProvider.LDAPServerMetadata.UserSearchSubtree) } - res.SetLdapServerMetadata(f10) + res.SetLdapServerMetadata(f9) } if cr.Spec.ForProvider.Logs != nil { - f11 := &svcsdk.Logs{} + f10 := &svcsdk.Logs{} if cr.Spec.ForProvider.Logs.Audit != nil { - f11.SetAudit(*cr.Spec.ForProvider.Logs.Audit) + f10.SetAudit(*cr.Spec.ForProvider.Logs.Audit) } if cr.Spec.ForProvider.Logs.General != nil { - f11.SetGeneral(*cr.Spec.ForProvider.Logs.General) + f10.SetGeneral(*cr.Spec.ForProvider.Logs.General) } - res.SetLogs(f11) + res.SetLogs(f10) } if cr.Spec.ForProvider.MaintenanceWindowStartTime != nil { - f12 := &svcsdk.WeeklyStartTime{} + f11 := &svcsdk.WeeklyStartTime{} if cr.Spec.ForProvider.MaintenanceWindowStartTime.DayOfWeek != nil { - f12.SetDayOfWeek(*cr.Spec.ForProvider.MaintenanceWindowStartTime.DayOfWeek) + f11.SetDayOfWeek(*cr.Spec.ForProvider.MaintenanceWindowStartTime.DayOfWeek) } if cr.Spec.ForProvider.MaintenanceWindowStartTime.TimeOfDay != nil { - f12.SetTimeOfDay(*cr.Spec.ForProvider.MaintenanceWindowStartTime.TimeOfDay) + f11.SetTimeOfDay(*cr.Spec.ForProvider.MaintenanceWindowStartTime.TimeOfDay) } if cr.Spec.ForProvider.MaintenanceWindowStartTime.TimeZone != nil { - f12.SetTimeZone(*cr.Spec.ForProvider.MaintenanceWindowStartTime.TimeZone) + f11.SetTimeZone(*cr.Spec.ForProvider.MaintenanceWindowStartTime.TimeZone) } - res.SetMaintenanceWindowStartTime(f12) + res.SetMaintenanceWindowStartTime(f11) } if cr.Spec.ForProvider.PubliclyAccessible != nil { res.SetPubliclyAccessible(*cr.Spec.ForProvider.PubliclyAccessible) } if cr.Spec.ForProvider.SecurityGroups != nil { - f14 := []*string{} - for _, f14iter := range cr.Spec.ForProvider.SecurityGroups { - var f14elem string - f14elem = *f14iter - f14 = append(f14, &f14elem) + f13 := []*string{} + for _, f13iter := range cr.Spec.ForProvider.SecurityGroups { + var f13elem string + f13elem = *f13iter + f13 = append(f13, &f13elem) } - res.SetSecurityGroups(f14) + res.SetSecurityGroups(f13) } if cr.Spec.ForProvider.StorageType != nil { res.SetStorageType(*cr.Spec.ForProvider.StorageType) } if cr.Spec.ForProvider.SubnetIDs != nil { - f16 := []*string{} - for _, f16iter := range cr.Spec.ForProvider.SubnetIDs { - var f16elem string - f16elem = *f16iter - f16 = append(f16, &f16elem) + f15 := []*string{} + for _, f15iter := range cr.Spec.ForProvider.SubnetIDs { + var f15elem string + f15elem = *f15iter + f15 = append(f15, &f15elem) } - res.SetSubnetIds(f16) + res.SetSubnetIds(f15) } if cr.Spec.ForProvider.Tags != nil { - f17 := map[string]*string{} - for f17key, f17valiter := range cr.Spec.ForProvider.Tags { - var f17val string - f17val = *f17valiter - f17[f17key] = &f17val - } - res.SetTags(f17) - } - if cr.Spec.ForProvider.Users != nil { - f18 := []*svcsdk.User{} - for _, f18iter := range cr.Spec.ForProvider.Users { - f18elem := &svcsdk.User{} - if f18iter.ConsoleAccess != nil { - f18elem.SetConsoleAccess(*f18iter.ConsoleAccess) - } - if f18iter.Groups != nil { - f18elemf1 := []*string{} - for _, f18elemf1iter := range f18iter.Groups { - var f18elemf1elem string - f18elemf1elem = *f18elemf1iter - f18elemf1 = append(f18elemf1, &f18elemf1elem) - } - f18elem.SetGroups(f18elemf1) - } - if f18iter.Password != nil { - f18elem.SetPassword(*f18iter.Password) - } - if f18iter.Username != nil { - f18elem.SetUsername(*f18iter.Username) - } - f18 = append(f18, f18elem) + f16 := map[string]*string{} + for f16key, f16valiter := range cr.Spec.ForProvider.Tags { + var f16val string + f16val = *f16valiter + f16[f16key] = &f16val } - res.SetUsers(f18) + res.SetTags(f16) } return res diff --git a/pkg/controller/mq/user/setup.go b/pkg/controller/mq/user/setup.go new file mode 100644 index 0000000000..02aa0dc76b --- /dev/null +++ b/pkg/controller/mq/user/setup.go @@ -0,0 +1,183 @@ +package user + +import ( + "context" + "time" + + "k8s.io/client-go/util/workqueue" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller" + + "github.com/aws/aws-sdk-go/aws" + svcsdk "github.com/aws/aws-sdk-go/service/mq" + svcsdkapi "github.com/aws/aws-sdk-go/service/mq/mqiface" + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + "github.com/crossplane/crossplane-runtime/pkg/event" + "github.com/crossplane/crossplane-runtime/pkg/logging" + "github.com/crossplane/crossplane-runtime/pkg/meta" + "github.com/crossplane/crossplane-runtime/pkg/ratelimiter" + "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" + "github.com/crossplane/crossplane-runtime/pkg/resource" + "github.com/pkg/errors" + + svcapitypes "github.com/crossplane/provider-aws/apis/mq/v1alpha1" + awsclients "github.com/crossplane/provider-aws/pkg/clients" + "github.com/crossplane/provider-aws/pkg/clients/mq" +) + +// SetupUser adds a controller that reconciles User. +func SetupUser(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, poll time.Duration) error { + name := managed.ControllerName(svcapitypes.UserGroupKind) + opts := []option{ + func(e *external) { + c := &custom{client: e.client, kube: e.kube, external: e} + e.isUpToDate = c.isUpToDate + e.preCreate = c.preCreate + e.postCreate = postCreate + e.preObserve = preObserve + e.preDelete = preDelete + e.postObserve = c.postObserve + e.preUpdate = c.preUpdate + e.postUpdate = c.postUpdate + }, + } + return ctrl.NewControllerManagedBy(mgr). + Named(name). + WithOptions(controller.Options{ + RateLimiter: ratelimiter.NewController(rl), + }). + For(&svcapitypes.User{}). + Complete(managed.NewReconciler(mgr, + resource.ManagedKind(svcapitypes.UserGroupVersionKind), + managed.WithInitializers(managed.NewDefaultProviderConfig(mgr.GetClient())), + managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}), + managed.WithPollInterval(poll), + managed.WithLogger(l.WithValues("controller", name)), + managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))))) +} + +type custom struct { + kube client.Client + client svcsdkapi.MQAPI + external *external +} + +func preObserve(_ context.Context, cr *svcapitypes.User, obj *svcsdk.DescribeUserInput) error { + obj.BrokerId = cr.Spec.ForProvider.BrokerID + obj.Username = awsclients.String(meta.GetExternalName(cr)) + return nil +} + +func (e *custom) postObserve(ctx context.Context, cr *svcapitypes.User, obj *svcsdk.DescribeUserResponse, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) { + if err != nil { + return managed.ExternalObservation{}, err + } + + // obj.Pending.PendingChange is nil if User is available + if obj.Pending != nil { + switch awsclients.StringValue(obj.Pending.PendingChange) { + case string(svcapitypes.ChangeType_CREATE): + cr.SetConditions(xpv1.Creating().WithMessage("wait for the next maintenance window or reboot the broker.")) + case string(svcapitypes.ChangeType_DELETE): + cr.SetConditions(xpv1.Deleting().WithMessage("wait for the next maintenance window or reboot the broker.")) + case string(svcapitypes.ChangeType_UPDATE): + cr.SetConditions(xpv1.Available().WithMessage("wait for the next maintenance window or reboot the broker.")) + } + return obs, nil + } + + cr.SetConditions(xpv1.Available()) + + pw, _, err := mq.GetPassword(ctx, e.kube, &cr.Spec.ForProvider.PasswordSecretRef, cr.Spec.WriteConnectionSecretToReference) + if resource.IgnoreNotFound(err) != nil || pw == "" { + return obs, errors.Wrap(err, "cannot get password from the given secret") + } + obs.ConnectionDetails = managed.ConnectionDetails{ + "Password": []byte(pw), + } + return obs, nil +} + +func preDelete(_ context.Context, cr *svcapitypes.User, obj *svcsdk.DeleteUserInput) (bool, error) { + obj.BrokerId = cr.Spec.ForProvider.BrokerID + obj.Username = awsclients.String(meta.GetExternalName(cr)) + + return false, nil +} + +func (e *custom) preCreate(ctx context.Context, cr *svcapitypes.User, obj *svcsdk.CreateUserRequest) error { + brokerState, err := e.client.DescribeBroker( + &svcsdk.DescribeBrokerInput{ + BrokerId: cr.Spec.ForProvider.BrokerID, + }, + ) + if err != nil { + return err + } + + if awsclients.StringValue(brokerState.BrokerState) != svcsdk.BrokerStateRunning || + awsclients.StringValue(brokerState.BrokerState) == svcsdk.BrokerStateDeletionInProgress { + return errors.New("broker is not ready for user creation " + awsclients.StringValue(brokerState.BrokerState)) + } + + pw, _, err := mq.GetPassword(ctx, e.kube, &cr.Spec.ForProvider.PasswordSecretRef, cr.Spec.WriteConnectionSecretToReference) + if resource.IgnoreNotFound(err) != nil { + return errors.Wrap(err, "cannot get password from the given secret") + } + obj.Password = awsclients.String(pw) + obj.Username = awsclients.String(cr.Name) + obj.BrokerId = cr.Spec.ForProvider.BrokerID + return nil +} + +func postCreate(_ context.Context, cr *svcapitypes.User, obj *svcsdk.CreateUserOutput, cre managed.ExternalCreation, err error) (managed.ExternalCreation, error) { + if err != nil { + return managed.ExternalCreation{}, err + } + meta.SetExternalName(cr, cr.Name) + return cre, nil +} + +func (e *custom) preUpdate(ctx context.Context, cr *svcapitypes.User, obj *svcsdk.UpdateUserRequest) error { + obj.BrokerId = cr.Spec.ForProvider.BrokerID + obj.Username = awsclients.String(cr.Name) + + pw, pwchanged, err := mq.GetPassword(ctx, e.kube, &cr.Spec.ForProvider.PasswordSecretRef, cr.Spec.WriteConnectionSecretToReference) + if err != nil { + return err + } + if pwchanged { + obj.Password = aws.String(pw) + } + return nil +} + +func (e *custom) postUpdate(ctx context.Context, cr *svcapitypes.User, obj *svcsdk.UpdateUserOutput, upd managed.ExternalUpdate, err error) (managed.ExternalUpdate, error) { + if err != nil { + return upd, err + } + + pw, _, err := mq.GetPassword(ctx, e.kube, &cr.Spec.ForProvider.PasswordSecretRef, cr.Spec.WriteConnectionSecretToReference) + if err != nil { + return upd, err + } + + var conn = managed.ConnectionDetails{ + xpv1.ResourceCredentialsSecretPasswordKey: []byte(pw), + } + return managed.ExternalUpdate{ConnectionDetails: conn}, nil +} + +func (e *custom) isUpToDate(cr *svcapitypes.User, obj *svcsdk.DescribeUserResponse) (bool, error) { + ctx := context.Background() + + if obj.Pending != nil { + return true, nil + } + _, pwChanged, err := mq.GetPassword(ctx, e.kube, &cr.Spec.ForProvider.PasswordSecretRef, cr.Spec.WriteConnectionSecretToReference) + if err != nil { + return false, err + } + return !pwChanged, nil +} diff --git a/pkg/controller/mq/user/zz_controller.go b/pkg/controller/mq/user/zz_controller.go new file mode 100644 index 0000000000..514c53132e --- /dev/null +++ b/pkg/controller/mq/user/zz_controller.go @@ -0,0 +1,220 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package user + +import ( + "context" + + svcapi "github.com/aws/aws-sdk-go/service/mq" + svcsdk "github.com/aws/aws-sdk-go/service/mq" + svcsdkapi "github.com/aws/aws-sdk-go/service/mq/mqiface" + "github.com/google/go-cmp/cmp" + "github.com/pkg/errors" + "sigs.k8s.io/controller-runtime/pkg/client" + + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + "github.com/crossplane/crossplane-runtime/pkg/meta" + "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" + cpresource "github.com/crossplane/crossplane-runtime/pkg/resource" + + svcapitypes "github.com/crossplane/provider-aws/apis/mq/v1alpha1" + awsclient "github.com/crossplane/provider-aws/pkg/clients" +) + +const ( + errUnexpectedObject = "managed resource is not an User resource" + + errCreateSession = "cannot create a new session" + errCreate = "cannot create User in AWS" + errUpdate = "cannot update User in AWS" + errDescribe = "failed to describe User" + errDelete = "failed to delete User" +) + +type connector struct { + kube client.Client + opts []option +} + +func (c *connector) Connect(ctx context.Context, mg cpresource.Managed) (managed.ExternalClient, error) { + cr, ok := mg.(*svcapitypes.User) + if !ok { + return nil, errors.New(errUnexpectedObject) + } + sess, err := awsclient.GetConfigV1(ctx, c.kube, mg, cr.Spec.ForProvider.Region) + if err != nil { + return nil, errors.Wrap(err, errCreateSession) + } + return newExternal(c.kube, svcapi.New(sess), c.opts), nil +} + +func (e *external) Observe(ctx context.Context, mg cpresource.Managed) (managed.ExternalObservation, error) { + cr, ok := mg.(*svcapitypes.User) + if !ok { + return managed.ExternalObservation{}, errors.New(errUnexpectedObject) + } + if meta.GetExternalName(cr) == "" { + return managed.ExternalObservation{ + ResourceExists: false, + }, nil + } + input := GenerateDescribeUserInput(cr) + if err := e.preObserve(ctx, cr, input); err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, "pre-observe failed") + } + resp, err := e.client.DescribeUserWithContext(ctx, input) + if err != nil { + return managed.ExternalObservation{ResourceExists: false}, awsclient.Wrap(cpresource.Ignore(IsNotFound, err), errDescribe) + } + currentSpec := cr.Spec.ForProvider.DeepCopy() + if err := e.lateInitialize(&cr.Spec.ForProvider, resp); err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, "late-init failed") + } + GenerateUser(resp).Status.AtProvider.DeepCopyInto(&cr.Status.AtProvider) + + upToDate, err := e.isUpToDate(cr, resp) + if err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, "isUpToDate check failed") + } + return e.postObserve(ctx, cr, resp, managed.ExternalObservation{ + ResourceExists: true, + ResourceUpToDate: upToDate, + ResourceLateInitialized: !cmp.Equal(&cr.Spec.ForProvider, currentSpec), + }, nil) +} + +func (e *external) Create(ctx context.Context, mg cpresource.Managed) (managed.ExternalCreation, error) { + cr, ok := mg.(*svcapitypes.User) + if !ok { + return managed.ExternalCreation{}, errors.New(errUnexpectedObject) + } + cr.Status.SetConditions(xpv1.Creating()) + input := GenerateCreateUserRequest(cr) + if err := e.preCreate(ctx, cr, input); err != nil { + return managed.ExternalCreation{}, errors.Wrap(err, "pre-create failed") + } + resp, err := e.client.CreateUserWithContext(ctx, input) + if err != nil { + return managed.ExternalCreation{}, awsclient.Wrap(err, errCreate) + } + + return e.postCreate(ctx, cr, resp, managed.ExternalCreation{}, err) +} + +func (e *external) Update(ctx context.Context, mg cpresource.Managed) (managed.ExternalUpdate, error) { + cr, ok := mg.(*svcapitypes.User) + if !ok { + return managed.ExternalUpdate{}, errors.New(errUnexpectedObject) + } + input := GenerateUpdateUserRequest(cr) + if err := e.preUpdate(ctx, cr, input); err != nil { + return managed.ExternalUpdate{}, errors.Wrap(err, "pre-update failed") + } + resp, err := e.client.UpdateUserWithContext(ctx, input) + return e.postUpdate(ctx, cr, resp, managed.ExternalUpdate{}, awsclient.Wrap(err, errUpdate)) +} + +func (e *external) Delete(ctx context.Context, mg cpresource.Managed) error { + cr, ok := mg.(*svcapitypes.User) + if !ok { + return errors.New(errUnexpectedObject) + } + cr.Status.SetConditions(xpv1.Deleting()) + input := GenerateDeleteUserInput(cr) + ignore, err := e.preDelete(ctx, cr, input) + if err != nil { + return errors.Wrap(err, "pre-delete failed") + } + if ignore { + return nil + } + resp, err := e.client.DeleteUserWithContext(ctx, input) + return e.postDelete(ctx, cr, resp, awsclient.Wrap(cpresource.Ignore(IsNotFound, err), errDelete)) +} + +type option func(*external) + +func newExternal(kube client.Client, client svcsdkapi.MQAPI, opts []option) *external { + e := &external{ + kube: kube, + client: client, + preObserve: nopPreObserve, + postObserve: nopPostObserve, + lateInitialize: nopLateInitialize, + isUpToDate: alwaysUpToDate, + preCreate: nopPreCreate, + postCreate: nopPostCreate, + preDelete: nopPreDelete, + postDelete: nopPostDelete, + preUpdate: nopPreUpdate, + postUpdate: nopPostUpdate, + } + for _, f := range opts { + f(e) + } + return e +} + +type external struct { + kube client.Client + client svcsdkapi.MQAPI + preObserve func(context.Context, *svcapitypes.User, *svcsdk.DescribeUserInput) error + postObserve func(context.Context, *svcapitypes.User, *svcsdk.DescribeUserResponse, managed.ExternalObservation, error) (managed.ExternalObservation, error) + lateInitialize func(*svcapitypes.UserParameters, *svcsdk.DescribeUserResponse) error + isUpToDate func(*svcapitypes.User, *svcsdk.DescribeUserResponse) (bool, error) + preCreate func(context.Context, *svcapitypes.User, *svcsdk.CreateUserRequest) error + postCreate func(context.Context, *svcapitypes.User, *svcsdk.CreateUserOutput, managed.ExternalCreation, error) (managed.ExternalCreation, error) + preDelete func(context.Context, *svcapitypes.User, *svcsdk.DeleteUserInput) (bool, error) + postDelete func(context.Context, *svcapitypes.User, *svcsdk.DeleteUserOutput, error) error + preUpdate func(context.Context, *svcapitypes.User, *svcsdk.UpdateUserRequest) error + postUpdate func(context.Context, *svcapitypes.User, *svcsdk.UpdateUserOutput, managed.ExternalUpdate, error) (managed.ExternalUpdate, error) +} + +func nopPreObserve(context.Context, *svcapitypes.User, *svcsdk.DescribeUserInput) error { + return nil +} + +func nopPostObserve(_ context.Context, _ *svcapitypes.User, _ *svcsdk.DescribeUserResponse, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) { + return obs, err +} +func nopLateInitialize(*svcapitypes.UserParameters, *svcsdk.DescribeUserResponse) error { + return nil +} +func alwaysUpToDate(*svcapitypes.User, *svcsdk.DescribeUserResponse) (bool, error) { + return true, nil +} + +func nopPreCreate(context.Context, *svcapitypes.User, *svcsdk.CreateUserRequest) error { + return nil +} +func nopPostCreate(_ context.Context, _ *svcapitypes.User, _ *svcsdk.CreateUserOutput, cre managed.ExternalCreation, err error) (managed.ExternalCreation, error) { + return cre, err +} +func nopPreDelete(context.Context, *svcapitypes.User, *svcsdk.DeleteUserInput) (bool, error) { + return false, nil +} +func nopPostDelete(_ context.Context, _ *svcapitypes.User, _ *svcsdk.DeleteUserOutput, err error) error { + return err +} +func nopPreUpdate(context.Context, *svcapitypes.User, *svcsdk.UpdateUserRequest) error { + return nil +} +func nopPostUpdate(_ context.Context, _ *svcapitypes.User, _ *svcsdk.UpdateUserOutput, upd managed.ExternalUpdate, err error) (managed.ExternalUpdate, error) { + return upd, err +} diff --git a/pkg/controller/mq/user/zz_conversions.go b/pkg/controller/mq/user/zz_conversions.go new file mode 100644 index 0000000000..d2f59927e0 --- /dev/null +++ b/pkg/controller/mq/user/zz_conversions.go @@ -0,0 +1,97 @@ +/* +Copyright 2021 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package user + +import ( + "github.com/aws/aws-sdk-go/aws/awserr" + svcsdk "github.com/aws/aws-sdk-go/service/mq" + + svcapitypes "github.com/crossplane/provider-aws/apis/mq/v1alpha1" +) + +// NOTE(muvaf): We return pointers in case the function needs to start with an +// empty object, hence need to return a new pointer. + +// GenerateDescribeUserInput returns input for read +// operation. +func GenerateDescribeUserInput(cr *svcapitypes.User) *svcsdk.DescribeUserInput { + res := &svcsdk.DescribeUserInput{} + + return res +} + +// GenerateUser returns the current state in the form of *svcapitypes.User. +func GenerateUser(resp *svcsdk.DescribeUserResponse) *svcapitypes.User { + cr := &svcapitypes.User{} + + return cr +} + +// GenerateCreateUserRequest returns a create input. +func GenerateCreateUserRequest(cr *svcapitypes.User) *svcsdk.CreateUserRequest { + res := &svcsdk.CreateUserRequest{} + + if cr.Spec.ForProvider.ConsoleAccess != nil { + res.SetConsoleAccess(*cr.Spec.ForProvider.ConsoleAccess) + } + if cr.Spec.ForProvider.Groups != nil { + f1 := []*string{} + for _, f1iter := range cr.Spec.ForProvider.Groups { + var f1elem string + f1elem = *f1iter + f1 = append(f1, &f1elem) + } + res.SetGroups(f1) + } + + return res +} + +// GenerateUpdateUserRequest returns an update input. +func GenerateUpdateUserRequest(cr *svcapitypes.User) *svcsdk.UpdateUserRequest { + res := &svcsdk.UpdateUserRequest{} + + if cr.Spec.ForProvider.ConsoleAccess != nil { + res.SetConsoleAccess(*cr.Spec.ForProvider.ConsoleAccess) + } + if cr.Spec.ForProvider.Groups != nil { + f2 := []*string{} + for _, f2iter := range cr.Spec.ForProvider.Groups { + var f2elem string + f2elem = *f2iter + f2 = append(f2, &f2elem) + } + res.SetGroups(f2) + } + + return res +} + +// GenerateDeleteUserInput returns a deletion input. +func GenerateDeleteUserInput(cr *svcapitypes.User) *svcsdk.DeleteUserInput { + res := &svcsdk.DeleteUserInput{} + + return res +} + +// IsNotFound returns whether the given error is of type NotFound or not. +func IsNotFound(err error) bool { + awsErr, ok := err.(awserr.Error) + return ok && awsErr.Code() == "NotFoundException" +}