proper names for constants; some clean up for log messages

This commit is contained in:
Murat Kabilov
2017-07-24 12:37:06 +02:00
parent 2161a0816c
commit d7e9142fc7
22 changed files with 122 additions and 122 deletions
+2 -2
View File
@@ -4,8 +4,8 @@ import "time"
// General kubernetes-related constants
const (
ListClustersURITemplate = "/apis/" + TPRVendor + "/" + TPRApiVersion + "/namespaces/%s/" + ResourceName // Namespace
WatchClustersURITemplate = "/apis/" + TPRVendor + "/" + TPRApiVersion + "/watch/namespaces/%s/" + ResourceName // Namespace
ListClustersURITemplate = "/apis/" + TPRGroup + "/" + TPRApiVersion + "/namespaces/%s/" + ResourceName // Namespace
WatchClustersURITemplate = "/apis/" + TPRGroup + "/" + TPRApiVersion + "/watch/namespaces/%s/" + ResourceName // Namespace
K8sVersion = "v1"
K8sAPIPath = "/api"
StatefulsetDeletionInterval = 1 * time.Second
+1 -1
View File
@@ -2,7 +2,7 @@ package constants
const (
PasswordLength = 64
UserSecretTemplate = "%s.%s.credentials." + TPRName + "." + TPRVendor // Username, ClusterName
UserSecretTemplate = "%s.%s.credentials." + TPRKind + "." + TPRGroup // Username, ClusterName
SuperuserKeyName = "superuser"
ReplicationUserKeyName = "replication"
RoleFlagSuperuser = "SUPERUSER"
+4 -3
View File
@@ -2,9 +2,10 @@ package constants
// Different properties of the PostgreSQL Third Party Resources
const (
TPRName = "postgresql"
TPRVendor = "acid.zalan.do"
TPRKind = "postgresql"
TPRGroup = "acid.zalan.do"
TPRDescription = "Managed PostgreSQL clusters"
TPRApiVersion = "v1"
ResourceName = TPRName + "s"
TPRName = TPRKind + "." + TPRKind
ResourceName = TPRKind + "s"
)
+1 -1
View File
@@ -37,5 +37,5 @@ func (c *Ext234Resize) ResizeFilesystem(deviceName string, commandExecutor func(
(strings.Contains(out, "on-line resizing required") && ext2fsSuccessRegexp.MatchString(out)) {
return nil
}
return fmt.Errorf("unrecognized output: %s, assuming error", out)
return fmt.Errorf("unrecognized output: %q, assuming error", out)
}
+1 -1
View File
@@ -47,7 +47,7 @@ func KubernetesRestClient(c *rest.Config) (rest.Interface, error) {
func(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(
schema.GroupVersion{
Group: constants.TPRVendor,
Group: constants.TPRGroup,
Version: constants.TPRApiVersion,
},
&spec.Postgresql{},
+4 -4
View File
@@ -66,11 +66,11 @@ func (s DefaultUserSyncStrategy) ExecuteSyncRequests(reqs []spec.PgSyncUserReque
switch r.Kind {
case spec.PGSyncUserAdd:
if err := s.createPgUser(r.User, db); err != nil {
return fmt.Errorf("could not create user '%s': %v", r.User.Name, err)
return fmt.Errorf("could not create user %q: %v", r.User.Name, err)
}
case spec.PGsyncUserAlter:
if err := s.alterPgUser(r.User, db); err != nil {
return fmt.Errorf("could not alter user '%s': %v", r.User.Name, err)
return fmt.Errorf("could not alter user %q: %v", r.User.Name, err)
}
default:
return fmt.Errorf("unrecognized operation: %v", r.Kind)
@@ -100,7 +100,7 @@ func (s DefaultUserSyncStrategy) createPgUser(user spec.PgUser, db *sql.DB) (err
_, err = db.Query(query) // TODO: Try several times
if err != nil {
err = fmt.Errorf("dB error: %s, query: %v", err, query)
err = fmt.Errorf("dB error: %v, query: %q", err, query)
return
}
@@ -122,7 +122,7 @@ func (s DefaultUserSyncStrategy) alterPgUser(user spec.PgUser, db *sql.DB) (err
_, err = db.Query(query) // TODO: Try several times
if err != nil {
err = fmt.Errorf("dB error: %s query %v", err, query)
err = fmt.Errorf("dB error: %v query %q", err, query)
return
}
+2 -2
View File
@@ -73,7 +73,7 @@ func TestPGUserPassword(t *testing.T) {
for _, tt := range pgUsers {
pwd := PGUserPassword(tt.in)
if pwd != tt.out {
t.Errorf("PgUserPassword expected: %s, got: %s", tt.out, pwd)
t.Errorf("PgUserPassword expected: %q, got: %q", tt.out, pwd)
}
}
}
@@ -81,7 +81,7 @@ func TestPGUserPassword(t *testing.T) {
func TestPrettyDiff(t *testing.T) {
for _, tt := range prettyDiffTest {
if actual := PrettyDiff(tt.inA, tt.inB); actual != tt.out {
t.Errorf("PrettyDiff expected: %s, got: %s", tt.out, actual)
t.Errorf("PrettyDiff expected: %q, got: %q", tt.out, actual)
}
}
}
+6 -6
View File
@@ -42,11 +42,11 @@ func (c *EBSVolumeResizer) VolumeBelongsToProvider(pv *v1.PersistentVolume) bool
func (c *EBSVolumeResizer) GetProviderVolumeID(pv *v1.PersistentVolume) (string, error) {
volumeID := pv.Spec.AWSElasticBlockStore.VolumeID
if volumeID == "" {
return "", fmt.Errorf("volume id is empty for volume %s", pv.Name)
return "", fmt.Errorf("volume id is empty for volume %q", pv.Name)
}
idx := strings.LastIndex(volumeID, constants.EBSVolumeIDStart) + 1
if idx == 0 {
return "", fmt.Errorf("malfored EBS volume id %s", volumeID)
return "", fmt.Errorf("malfored EBS volume id %q", volumeID)
}
return volumeID[idx:], nil
}
@@ -60,7 +60,7 @@ func (c *EBSVolumeResizer) ResizeVolume(volumeId string, newSize int64) error {
}
vol := volumeOutput.Volumes[0]
if *vol.VolumeId != volumeId {
return fmt.Errorf("describe volume %s returned information about a non-matching volume %s", volumeId, *vol.VolumeId)
return fmt.Errorf("describe volume %q returned information about a non-matching volume %q", volumeId, *vol.VolumeId)
}
if *vol.Size == newSize {
// nothing to do
@@ -74,7 +74,7 @@ func (c *EBSVolumeResizer) ResizeVolume(volumeId string, newSize int64) error {
state := *output.VolumeModification.ModificationState
if state == constants.EBSVolumeStateFailed {
return fmt.Errorf("could not modify persistent volume %s: modification state failed", volumeId)
return fmt.Errorf("could not modify persistent volume %q: modification state failed", volumeId)
}
if state == "" {
return fmt.Errorf("received empty modification status")
@@ -91,10 +91,10 @@ func (c *EBSVolumeResizer) ResizeVolume(volumeId string, newSize int64) error {
return false, fmt.Errorf("could not describe volume modification: %v", err)
}
if len(out.VolumesModifications) != 1 {
return false, fmt.Errorf("describe volume modification didn't return one record for volume \"%s\"", volumeId)
return false, fmt.Errorf("describe volume modification didn't return one record for volume %q", volumeId)
}
if *out.VolumesModifications[0].VolumeId != volumeId {
return false, fmt.Errorf("non-matching volume id when describing modifications: \"%s\" is different from \"%s\"",
return false, fmt.Errorf("non-matching volume id when describing modifications: %q is different from %q",
*out.VolumesModifications[0].VolumeId, volumeId)
}
return *out.VolumesModifications[0].ModificationState != constants.EBSVolumeStateModifying, nil