Skip to content

Commit 4c04e60

Browse files
authored
merge pointer and value receivers to a common kind (#1205)
1 parent 2b7f78f commit 4c04e60

File tree

3 files changed

+49
-49
lines changed

3 files changed

+49
-49
lines changed

api/v1/mongodbcommunity_types.go

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -623,24 +623,24 @@ type MongoDBCommunity struct {
623623
Status MongoDBCommunityStatus `json:"status,omitempty"`
624624
}
625625

626-
func (m MongoDBCommunity) GetMongodConfiguration() MongodConfiguration {
626+
func (m *MongoDBCommunity) GetMongodConfiguration() MongodConfiguration {
627627
mongodConfig := NewMongodConfiguration()
628628
for k, v := range m.Spec.AdditionalMongodConfig.Object {
629629
mongodConfig.SetOption(k, v)
630630
}
631631
return mongodConfig
632632
}
633633

634-
func (m MongoDBCommunity) GetAgentPasswordSecretNamespacedName() types.NamespacedName {
634+
func (m *MongoDBCommunity) GetAgentPasswordSecretNamespacedName() types.NamespacedName {
635635
return types.NamespacedName{Name: m.Name + "-agent-password", Namespace: m.Namespace}
636636
}
637637

638-
func (m MongoDBCommunity) GetAgentKeyfileSecretNamespacedName() types.NamespacedName {
638+
func (m *MongoDBCommunity) GetAgentKeyfileSecretNamespacedName() types.NamespacedName {
639639
return types.NamespacedName{Name: m.Name + "-keyfile", Namespace: m.Namespace}
640640
}
641641

642-
func (m MongoDBCommunity) GetOwnerReferences() []metav1.OwnerReference {
643-
ownerReference := *metav1.NewControllerRef(&m, schema.GroupVersionKind{
642+
func (m *MongoDBCommunity) GetOwnerReferences() []metav1.OwnerReference {
643+
ownerReference := *metav1.NewControllerRef(m, schema.GroupVersionKind{
644644
Group: GroupVersion.Group,
645645
Version: GroupVersion.Version,
646646
Kind: m.Kind,
@@ -650,7 +650,7 @@ func (m MongoDBCommunity) GetOwnerReferences() []metav1.OwnerReference {
650650

651651
// GetScramOptions returns a set of Options that are used to configure scram
652652
// authentication.
653-
func (m MongoDBCommunity) GetScramOptions() scram.Options {
653+
func (m *MongoDBCommunity) GetScramOptions() scram.Options {
654654
ignoreUnknownUsers := true
655655
if m.Spec.Security.Authentication.IgnoreUnknownUsers != nil {
656656
ignoreUnknownUsers = *m.Spec.Security.Authentication.IgnoreUnknownUsers
@@ -687,7 +687,7 @@ func (m MongoDBCommunity) GetScramOptions() scram.Options {
687687

688688
// GetScramUsers converts all of the users from the spec into users
689689
// that can be used to configure scram authentication.
690-
func (m MongoDBCommunity) GetScramUsers() []scram.User {
690+
func (m *MongoDBCommunity) GetScramUsers() []scram.User {
691691
users := make([]scram.User, len(m.Spec.Users))
692692
for i, u := range m.Spec.Users {
693693
roles := make([]scram.Role, len(u.Roles))
@@ -724,7 +724,7 @@ func (m MongoDBCommunity) GetScramUsers() []scram.User {
724724

725725
// IsStillScaling returns true if this resource is currently scaling,
726726
// considering both arbiters and regular members.
727-
func (m MongoDBCommunity) IsStillScaling() bool {
727+
func (m *MongoDBCommunity) IsStillScaling() bool {
728728
arbiters := automationConfigReplicasScaler{
729729
current: m.CurrentArbiters(),
730730
desired: m.DesiredArbiters(),
@@ -737,7 +737,7 @@ func (m MongoDBCommunity) IsStillScaling() bool {
737737
// AutomationConfigMembersThisReconciliation determines the correct number of
738738
// automation config replica set members based on our desired number, and our
739739
// current number.
740-
func (m MongoDBCommunity) AutomationConfigMembersThisReconciliation() int {
740+
func (m *MongoDBCommunity) AutomationConfigMembersThisReconciliation() int {
741741
return scale.ReplicasThisReconciliation(automationConfigReplicasScaler{
742742
current: m.Status.CurrentMongoDBMembers,
743743
desired: m.Spec.Members,
@@ -749,7 +749,7 @@ func (m MongoDBCommunity) AutomationConfigMembersThisReconciliation() int {
749749
// current number.
750750
//
751751
// Will not update arbiters until members have reached desired number.
752-
func (m MongoDBCommunity) AutomationConfigArbitersThisReconciliation() int {
752+
func (m *MongoDBCommunity) AutomationConfigArbitersThisReconciliation() int {
753753
if scale.IsStillScaling(m) {
754754
return m.Status.CurrentMongoDBArbiters
755755
}
@@ -762,12 +762,12 @@ func (m MongoDBCommunity) AutomationConfigArbitersThisReconciliation() int {
762762
}
763763

764764
// MongoURI returns a mongo uri which can be used to connect to this deployment
765-
func (m MongoDBCommunity) MongoURI(clusterDomain string) string {
765+
func (m *MongoDBCommunity) MongoURI(clusterDomain string) string {
766766
return fmt.Sprintf("mongodb://%s/?replicaSet=%s", strings.Join(m.Hosts(clusterDomain), ","), m.Name)
767767
}
768768

769769
// MongoSRVURI returns a mongo srv uri which can be used to connect to this deployment
770-
func (m MongoDBCommunity) MongoSRVURI(clusterDomain string) string {
770+
func (m *MongoDBCommunity) MongoSRVURI(clusterDomain string) string {
771771
if clusterDomain == "" {
772772
clusterDomain = defaultClusterDomain
773773
}
@@ -776,7 +776,7 @@ func (m MongoDBCommunity) MongoSRVURI(clusterDomain string) string {
776776

777777
// MongoAuthUserURI returns a mongo uri which can be used to connect to this deployment
778778
// and includes the authentication data for the user
779-
func (m MongoDBCommunity) MongoAuthUserURI(user scram.User, password string, clusterDomain string) string {
779+
func (m *MongoDBCommunity) MongoAuthUserURI(user scram.User, password string, clusterDomain string) string {
780780
return fmt.Sprintf("mongodb://%s:%s@%s/%s?replicaSet=%s&ssl=%t",
781781
url.QueryEscape(user.Username),
782782
url.QueryEscape(password),
@@ -788,7 +788,7 @@ func (m MongoDBCommunity) MongoAuthUserURI(user scram.User, password string, clu
788788

789789
// MongoAuthUserSRVURI returns a mongo srv uri which can be used to connect to this deployment
790790
// and includes the authentication data for the user
791-
func (m MongoDBCommunity) MongoAuthUserSRVURI(user scram.User, password string, clusterDomain string) string {
791+
func (m *MongoDBCommunity) MongoAuthUserSRVURI(user scram.User, password string, clusterDomain string) string {
792792
if clusterDomain == "" {
793793
clusterDomain = defaultClusterDomain
794794
}
@@ -803,7 +803,7 @@ func (m MongoDBCommunity) MongoAuthUserSRVURI(user scram.User, password string,
803803
m.Spec.Security.TLS.Enabled)
804804
}
805805

806-
func (m MongoDBCommunity) Hosts(clusterDomain string) []string {
806+
func (m *MongoDBCommunity) Hosts(clusterDomain string) []string {
807807
hosts := make([]string, m.Spec.Members)
808808

809809
if clusterDomain == "" {
@@ -822,69 +822,69 @@ func (m MongoDBCommunity) Hosts(clusterDomain string) []string {
822822
}
823823

824824
// ServiceName returns the name of the Service that should be created for this resource.
825-
func (m MongoDBCommunity) ServiceName() string {
825+
func (m *MongoDBCommunity) ServiceName() string {
826826
serviceName := m.Spec.StatefulSetConfiguration.SpecWrapper.Spec.ServiceName
827827
if serviceName != "" {
828828
return serviceName
829829
}
830830
return m.Name + "-svc"
831831
}
832832

833-
func (m MongoDBCommunity) ArbiterNamespacedName() types.NamespacedName {
833+
func (m *MongoDBCommunity) ArbiterNamespacedName() types.NamespacedName {
834834
return types.NamespacedName{Namespace: m.Namespace, Name: m.Name + "-arb"}
835835
}
836836

837-
func (m MongoDBCommunity) AutomationConfigSecretName() string {
837+
func (m *MongoDBCommunity) AutomationConfigSecretName() string {
838838
return m.Name + "-config"
839839
}
840840

841841
// TLSCaCertificateSecretNamespacedName will get the namespaced name of the Secret containing the CA certificate
842842
// As the Secret will be mounted to our pods, it has to be in the same namespace as the MongoDB resource
843-
func (m MongoDBCommunity) TLSCaCertificateSecretNamespacedName() types.NamespacedName {
843+
func (m *MongoDBCommunity) TLSCaCertificateSecretNamespacedName() types.NamespacedName {
844844
return types.NamespacedName{Name: m.Spec.Security.TLS.CaCertificateSecret.Name, Namespace: m.Namespace}
845845
}
846846

847847
// TLSConfigMapNamespacedName will get the namespaced name of the ConfigMap containing the CA certificate
848848
// As the ConfigMap will be mounted to our pods, it has to be in the same namespace as the MongoDB resource
849-
func (m MongoDBCommunity) TLSConfigMapNamespacedName() types.NamespacedName {
849+
func (m *MongoDBCommunity) TLSConfigMapNamespacedName() types.NamespacedName {
850850
return types.NamespacedName{Name: m.Spec.Security.TLS.CaConfigMap.Name, Namespace: m.Namespace}
851851
}
852852

853853
// TLSSecretNamespacedName will get the namespaced name of the Secret containing the server certificate and key
854-
func (m MongoDBCommunity) TLSSecretNamespacedName() types.NamespacedName {
854+
func (m *MongoDBCommunity) TLSSecretNamespacedName() types.NamespacedName {
855855
return types.NamespacedName{Name: m.Spec.Security.TLS.CertificateKeySecret.Name, Namespace: m.Namespace}
856856
}
857857

858858
// PrometheusTLSSecretNamespacedName will get the namespaced name of the Secret containing the server certificate and key
859-
func (m MongoDBCommunity) PrometheusTLSSecretNamespacedName() types.NamespacedName {
859+
func (m *MongoDBCommunity) PrometheusTLSSecretNamespacedName() types.NamespacedName {
860860
return types.NamespacedName{Name: m.Spec.Prometheus.TLSSecretRef.Name, Namespace: m.Namespace}
861861
}
862862

863-
func (m MongoDBCommunity) TLSOperatorCASecretNamespacedName() types.NamespacedName {
863+
func (m *MongoDBCommunity) TLSOperatorCASecretNamespacedName() types.NamespacedName {
864864
return types.NamespacedName{Name: m.Name + "-ca-certificate", Namespace: m.Namespace}
865865
}
866866

867867
// TLSOperatorSecretNamespacedName will get the namespaced name of the Secret created by the operator
868868
// containing the combined certificate and key.
869-
func (m MongoDBCommunity) TLSOperatorSecretNamespacedName() types.NamespacedName {
869+
func (m *MongoDBCommunity) TLSOperatorSecretNamespacedName() types.NamespacedName {
870870
return types.NamespacedName{Name: m.Name + "-server-certificate-key", Namespace: m.Namespace}
871871
}
872872

873873
// PrometheusTLSOperatorSecretNamespacedName will get the namespaced name of the Secret created by the operator
874874
// containing the combined certificate and key.
875-
func (m MongoDBCommunity) PrometheusTLSOperatorSecretNamespacedName() types.NamespacedName {
875+
func (m *MongoDBCommunity) PrometheusTLSOperatorSecretNamespacedName() types.NamespacedName {
876876
return types.NamespacedName{Name: m.Name + "-prometheus-certificate-key", Namespace: m.Namespace}
877877
}
878878

879-
func (m MongoDBCommunity) NamespacedName() types.NamespacedName {
879+
func (m *MongoDBCommunity) NamespacedName() types.NamespacedName {
880880
return types.NamespacedName{Name: m.Name, Namespace: m.Namespace}
881881
}
882882

883-
func (m MongoDBCommunity) DesiredReplicas() int {
883+
func (m *MongoDBCommunity) DesiredReplicas() int {
884884
return m.Spec.Members
885885
}
886886

887-
func (m MongoDBCommunity) CurrentReplicas() int {
887+
func (m *MongoDBCommunity) CurrentReplicas() int {
888888
return m.Status.CurrentStatefulSetReplicas
889889
}
890890

@@ -898,26 +898,26 @@ func (m MongoDBCommunity) CurrentReplicas() int {
898898
//
899899
// This was done to simplify the process of scaling arbiters, *after* members
900900
// have reached the desired amount of replicas.
901-
func (m MongoDBCommunity) ForcedIndividualScaling() bool {
901+
func (m *MongoDBCommunity) ForcedIndividualScaling() bool {
902902
return false
903903
}
904904

905-
func (m MongoDBCommunity) DesiredArbiters() int {
905+
func (m *MongoDBCommunity) DesiredArbiters() int {
906906
return m.Spec.Arbiters
907907
}
908908

909-
func (m MongoDBCommunity) CurrentArbiters() int {
909+
func (m *MongoDBCommunity) CurrentArbiters() int {
910910
return m.Status.CurrentStatefulSetArbitersReplicas
911911
}
912912

913-
func (m MongoDBCommunity) GetMongoDBVersion() string {
913+
func (m *MongoDBCommunity) GetMongoDBVersion() string {
914914
return m.Spec.Version
915915
}
916916

917917
// GetMongoDBVersionForAnnotation returns the MDB version used to annotate the object.
918918
// Here it's the same as GetMongoDBVersion, but a different name is used in order to make
919919
// the usage clearer in enterprise (where it's a method of OpsManager but is used for the AppDB)
920-
func (m MongoDBCommunity) GetMongoDBVersionForAnnotation() string {
920+
func (m *MongoDBCommunity) GetMongoDBVersionForAnnotation() string {
921921
return m.GetMongoDBVersion()
922922
}
923923

@@ -939,41 +939,41 @@ func (m *MongoDBCommunity) StatefulSetArbitersThisReconciliation() int {
939939

940940
// GetUpdateStrategyType returns the type of RollingUpgradeStrategy that the
941941
// MongoDB StatefulSet should be configured with.
942-
func (m MongoDBCommunity) GetUpdateStrategyType() appsv1.StatefulSetUpdateStrategyType {
942+
func (m *MongoDBCommunity) GetUpdateStrategyType() appsv1.StatefulSetUpdateStrategyType {
943943
if !m.IsChangingVersion() {
944944
return appsv1.RollingUpdateStatefulSetStrategyType
945945
}
946946
return appsv1.OnDeleteStatefulSetStrategyType
947947
}
948948

949949
// IsChangingVersion returns true if an attempted version change is occurring.
950-
func (m MongoDBCommunity) IsChangingVersion() bool {
950+
func (m *MongoDBCommunity) IsChangingVersion() bool {
951951
lastVersion := m.getLastVersion()
952952
return lastVersion != "" && lastVersion != m.Spec.Version
953953
}
954954

955955
// GetLastVersion returns the MDB version the statefulset was configured with.
956-
func (m MongoDBCommunity) getLastVersion() string {
957-
return annotations.GetAnnotation(&m, annotations.LastAppliedMongoDBVersion)
956+
func (m *MongoDBCommunity) getLastVersion() string {
957+
return annotations.GetAnnotation(m, annotations.LastAppliedMongoDBVersion)
958958
}
959959

960-
func (m MongoDBCommunity) HasSeparateDataAndLogsVolumes() bool {
960+
func (m *MongoDBCommunity) HasSeparateDataAndLogsVolumes() bool {
961961
return true
962962
}
963963

964-
func (m MongoDBCommunity) GetAnnotations() map[string]string {
964+
func (m *MongoDBCommunity) GetAnnotations() map[string]string {
965965
return m.Annotations
966966
}
967967

968-
func (m MongoDBCommunity) DataVolumeName() string {
968+
func (m *MongoDBCommunity) DataVolumeName() string {
969969
return "data-volume"
970970
}
971971

972-
func (m MongoDBCommunity) LogsVolumeName() string {
972+
func (m *MongoDBCommunity) LogsVolumeName() string {
973973
return "logs-volume"
974974
}
975975

976-
func (m MongoDBCommunity) NeedsAutomationConfigVolume() bool {
976+
func (m *MongoDBCommunity) NeedsAutomationConfigVolume() bool {
977977
return true
978978
}
979979

controllers/construct/build_statefulset_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestMultipleCalls_DoNotCauseSideEffects(t *testing.T) {
4545
t.Setenv(AgentImageEnv, "agent-image")
4646

4747
mdb := newTestReplicaSet()
48-
stsFunc := BuildMongoDBReplicaSetStatefulSetModificationFunction(&mdb, mdb)
48+
stsFunc := BuildMongoDBReplicaSetStatefulSetModificationFunction(&mdb, &mdb)
4949
sts := &appsv1.StatefulSet{}
5050

5151
t.Run("1st Call", func(t *testing.T) {
@@ -69,7 +69,7 @@ func TestManagedSecurityContext(t *testing.T) {
6969
t.Setenv(podtemplatespec.ManagedSecurityContextEnv, "true")
7070

7171
mdb := newTestReplicaSet()
72-
stsFunc := BuildMongoDBReplicaSetStatefulSetModificationFunction(&mdb, mdb)
72+
stsFunc := BuildMongoDBReplicaSetStatefulSetModificationFunction(&mdb, &mdb)
7373

7474
sts := &appsv1.StatefulSet{}
7575
stsFunc(sts)

controllers/replica_set_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,16 +406,16 @@ func (r *ReplicaSetReconciler) shouldRunInOrder(mdb mdbv1.MongoDBCommunity) bool
406406
}
407407

408408
// if we are scaling up, we need to make sure the StatefulSet is scaled up first.
409-
if scale.IsScalingUp(mdb) || mdb.CurrentArbiters() < mdb.DesiredArbiters() {
410-
if scale.HasZeroReplicas(mdb) {
409+
if scale.IsScalingUp(&mdb) || mdb.CurrentArbiters() < mdb.DesiredArbiters() {
410+
if scale.HasZeroReplicas(&mdb) {
411411
r.log.Debug("Scaling up the ReplicaSet when there is no replicas, the Automation Config must be updated first")
412412
return true
413413
}
414414
r.log.Debug("Scaling up the ReplicaSet, the StatefulSet must be updated first")
415415
return false
416416
}
417417

418-
if scale.IsScalingDown(mdb) {
418+
if scale.IsScalingDown(&mdb) {
419419
r.log.Debug("Scaling down the ReplicaSet, the Automation Config must be updated first")
420420
return true
421421
}
@@ -636,7 +636,7 @@ func (r ReplicaSetReconciler) buildAutomationConfig(mdb mdbv1.MongoDBCommunity)
636636
}
637637

638638
auth := automationconfig.Auth{}
639-
if err := scram.Enable(&auth, r.client, mdb); err != nil {
639+
if err := scram.Enable(&auth, r.client, &mdb); err != nil {
640640
return automationconfig.AutomationConfig{}, fmt.Errorf("could not configure scram authentication: %s", err)
641641
}
642642

@@ -715,7 +715,7 @@ func buildStatefulSet(mdb mdbv1.MongoDBCommunity) (appsv1.StatefulSet, error) {
715715
}
716716

717717
func buildStatefulSetModificationFunction(mdb mdbv1.MongoDBCommunity) statefulset.Modification {
718-
commonModification := construct.BuildMongoDBReplicaSetStatefulSetModificationFunction(&mdb, mdb)
718+
commonModification := construct.BuildMongoDBReplicaSetStatefulSetModificationFunction(&mdb, &mdb)
719719
return statefulset.Apply(
720720
commonModification,
721721
statefulset.WithOwnerReference(mdb.GetOwnerReferences()),

0 commit comments

Comments
 (0)