-
Notifications
You must be signed in to change notification settings - Fork 21
Conversation
8a007d2
to
8d81a23
Compare
8ce6d07
to
7da5bfb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't gone through FSS in detail but the same kind of changes apply 🙂
pkg/oci/client/client.go
Outdated
func FromConfig(cfg *Config) (ProvisionerClient, error) { | ||
config, err := newConfigurationProvider(cfg) | ||
func FromConfig(logger *zap.SugaredLogger, cfg *Config) (ProvisionerClient, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n
cmd/main.go
Outdated
@@ -69,25 +80,25 @@ func main() { | |||
// to use to communicate with Kubernetes | |||
config, err := clientcmd.BuildConfigFromFlags(*master, *kubeconfig) | |||
if err != nil { | |||
glog.Fatalf("Failed to load config: %v", err) | |||
logger.Fatalf("Failed to load config: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.With(zap.Error(err)).Fatal("Failed to load config")
cmd/main.go
Outdated
} | ||
|
||
clientset, err := kubernetes.NewForConfig(config) | ||
if err != nil { | ||
glog.Fatalf("Failed to create client: %v", err) | ||
logger.Fatalf("Failed to create client: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.With(zap.Error(err)).Fatal("Failed to create Kubernetes client")
cmd/main.go
Outdated
} | ||
|
||
// The controller needs to know what the server version is because out-of-tree | ||
// provisioners aren't officially supported until 1.5 | ||
serverVersion, err := clientset.Discovery().ServerVersion() | ||
if err != nil { | ||
glog.Fatalf("Error getting server version: %v", err) | ||
logger.Fatalf("Error getting server version: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.With(zap.Error(err)).Fatal("Failed to get kube-apiserver version")
cmd/main.go
Outdated
@@ -96,21 +107,22 @@ func main() { | |||
provisionerType = core.ProvisionerNameBlock | |||
} | |||
|
|||
glog.Infof("Starting volume provisioner in %s mode", provisionerType) | |||
logger.With("provisionerType", provisionerType).Info("Starting volume provisioner in %s mode", provisionerType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger = logger.With("provisionerType", provisionerType)
logger.Info("Starting volume provisioner in %q mode", provisionerType)
pkg/provisioner/block/block.go
Outdated
|
||
if volumeRoundingEnabled(options.Parameters) { | ||
if block.volumeRoundingEnabled && block.minVolumeSize.Cmp(capacity) == 1 { | ||
glog.Warningf("PVC requested storage less than %s. Rounding up to ensure volume creation", block.minVolumeSize.String()) | ||
block.logger.Warnf("PVC requested storage less than %s. Rounding up to ensure volume creation.", block.minVolumeSize.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.Warn("Attempted to provision volume with a capacity less than the minimum. Rounding up to ensure volume creation.")
pkg/provisioner/block/block.go
Outdated
|
||
volSizeMB = int(roundUpSize(block.minVolumeSize.Value(), 1024*1024)) | ||
capacity = block.minVolumeSize | ||
} | ||
} | ||
|
||
glog.Infof("Creating volume size=%v AD=%s compartmentOCID=%q", volSizeMB, *ad.Name, block.client.CompartmentOCID()) | ||
block.logger.With("volumeSize", volSizeMB).With("name", *ad.Name).With("compartmentOCID", block.client.CompartmentOCID()).Info("Creating volume.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed (see log in comment above with all this)
pkg/provisioner/block/block.go
Outdated
@@ -171,7 +174,7 @@ func (block *blockProvisioner) Provision(options controller.VolumeOptions, ad *i | |||
} | |||
|
|||
if value, ok := options.PVC.Annotations[ociVolumeBackupID]; ok { | |||
glog.Infof("Creating volume from backup ID %s", value) | |||
block.logger.With("volumeBackupOCID", value).Info("Creating volume from backup.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/block.logger/logger/
pkg/provisioner/core/provisioner.go
Outdated
configPath, ok := os.LookupEnv("CONFIG_YAML_FILENAME") | ||
if !ok { | ||
configPath = configFilePath | ||
} | ||
|
||
f, err := os.Open(configPath) | ||
if err != nil { | ||
glog.Fatalf("Unable to load volume provisioner configuration file: %v", configPath) | ||
logger.With("configPath", configPath).Fatal("Unable to load volume provisioner configuration file.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.With(zap.Error(err), "configPath", configPath).Fatal("Unable to load volume provisioner configuration file.")
pkg/provisioner/core/utils.go
Outdated
@@ -80,7 +79,7 @@ func (p *OCIProvisioner) chooseAvailabilityDomain(ctx context.Context, pvc *v1.P | |||
return "", nil, fmt.Errorf("failed to choose availability domain; no zone labels (%q) on nodes", metav1.LabelZoneFailureDomain) | |||
} | |||
availabilityDomainName = util.ChooseZoneForVolume(validADs, pvc.Name) | |||
glog.Infof("Zone not specified so %s selected", availabilityDomainName) | |||
p.logger.With("zone", availabilityDomainName).Info("Zone not specified, selected alternative zone.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p.logger.With("availabilityDomain", availabilityDomainName).Info("No availability domain provided. Selecting one automatically.")
daedd0c
to
96f725d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we're getting into the real nitty-gritty 🙂
pkg/provisioner/block/block.go
Outdated
|
||
if volumeRoundingEnabled(options.Parameters) { | ||
if block.volumeRoundingEnabled && block.minVolumeSize.Cmp(capacity) == 1 { | ||
glog.Warningf("PVC requested storage less than %s. Rounding up to ensure volume creation", block.minVolumeSize.String()) | ||
|
||
logger.Warn("Attempted to provision volume with a capacity less than the minimum. Rounding up to ensure volume creation.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably move this log down a line and then add a .With("roundedVolumeSize", volSizeMB)
pkg/provisioner/block/block.go
Outdated
glog.Infof("Volume size: %dMB", volSizeMB) | ||
|
||
logger := block.logger.With( | ||
"compartmentID", block.client.CompartmentOCID(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On reflection adding the "compartmentID"
and "tenancyID"
fields should be moved to the constructor (NewBlockProvisioner
) so that they're applied in both the Provision()
and Delete()
methods.
pkg/provisioner/fss/fss.go
Outdated
return &filesystemProvisioner{ | ||
client: client, | ||
logger: logger, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the "compartmentID"
and "tenancyID"
fields here (same as suggested above in NewBlockProvisioner()
)
pkg/provisioner/fss/fss_test.go
Outdated
@@ -19,6 +19,7 @@ import ( | |||
"reflect" | |||
"testing" | |||
|
|||
"go.uber.org/zap" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import grouping
pkg/provisioner/fss/fss.go
Outdated
ctx, cancel := context.WithTimeout(ctx, fsp.client.Timeout()) | ||
defer cancel() | ||
if _, err := fsp.client.FSS().DeleteExport(ctx, filestorage.DeleteExportRequest{ | ||
ExportId: &exportID, | ||
}); err != nil { | ||
if !provisioner.IsNotFound(err) { | ||
glog.Errorf("Failed to delete export exportID=%q: %v", exportID, err) | ||
logger.With(zap.Error(err), "exportOCID", exportID).Error("Failed to delete export.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove exportID
field (will be assigned above).
@@ -171,7 +178,7 @@ func (block *blockProvisioner) Provision(options controller.VolumeOptions, ad *i | |||
} | |||
|
|||
if value, ok := options.PVC.Annotations[ociVolumeBackupID]; ok { | |||
glog.Infof("Creating volume from backup ID %s", value) | |||
logger.With("volumeBackupOCID", value).Info("Creating volume from backup.") | |||
volumeDetails.SourceDetails = &core.VolumeSourceFromVolumeBackupDetails{Id: &value} | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below log that we're waitForVolumeAvailable()
.With("volumeID", *newVolume.Id)
pkg/provisioner/block/block_test.go
Outdated
@@ -146,6 +154,9 @@ func TestCreateVolumeFailure(t *testing.T) { | |||
} | |||
|
|||
func TestVolumeRoundingLogic(t *testing.T) { | |||
|
|||
logger := zap.S() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't bother assigning; just pass zap.S()
directly.
pkg/provisioner/block/block_test.go
Outdated
@@ -100,6 +105,9 @@ func TestCreateVolumeFromBackup(t *testing.T) { | |||
} | |||
|
|||
func TestCreateVolumeFailure(t *testing.T) { | |||
|
|||
logger := zap.S() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't bother assigning; just pass zap.S()
directly.
pkg/provisioner/block/block_test.go
Outdated
@@ -61,6 +63,9 @@ func TestResolveFSTypeWhenConfigured(t *testing.T) { | |||
|
|||
func TestCreateVolumeFromBackup(t *testing.T) { | |||
// test creating a volume from an existing backup | |||
|
|||
logger := zap.S() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't bother assigning; just pass zap.S()
directly.
pkg/provisioner/core/provisioner.go
Outdated
@@ -20,7 +20,8 @@ import ( | |||
"strings" | |||
"time" | |||
|
|||
"github.com/golang/glog" | |||
"go.uber.org/zap" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import grouping
fde08e3
to
543a114
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more
pkg/provisioner/fss/fss.go
Outdated
return &filesystemProvisioner{ | ||
client: client, | ||
logger: logger.With( | ||
"compartmentID", client.CompartmentOCID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you be calling these as they're methods?
pkg/provisioner/fss/fss.go
Outdated
// Create the FileSystem. | ||
var fsID string | ||
{ | ||
ctx, cancel := context.WithTimeout(ctx, fsp.client.Timeout()) | ||
defer cancel() | ||
logger.Info("Creating FileSystem") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log above outside of this block.
pkg/provisioner/fss/fss.go
Outdated
@@ -195,13 +206,13 @@ func (fsp *filesystemProvisioner) Provision(options controller.VolumeOptions, ad | |||
PrivateIpId: &id, | |||
}) | |||
if err != nil { | |||
glog.Errorf("Failed to retrieve IP address for mount target privateIpID=%q: %v", id, err) | |||
logger.Errorf("Failed to retrieve IP address for mount target privateIpID=%q: %v", id, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.With(zap.Error(err), "privateIPID", id)
glog.Infof("Deleting export for filesystemID %v", filesystemID) | ||
logger := fsp.logger.With( | ||
"fileSystemOCID", filesystemID, | ||
"volumeOCID", volume, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not done.
pkg/provisioner/fss/fss.go
Outdated
return nil, err | ||
} | ||
serverIP = *getPrivateIPResponse.PrivateIp.IpAddress | ||
} | ||
|
||
glog.Infof("Creating persistent volume on mount target with private IP address %s", serverIP) | ||
logger.With("privateIP", serverIP).Info("Creating persistent volume on mount target with private IP address.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe reword message to something along the lines of "Chose Mount Target Private IP"?
}, | ||
}) | ||
if err != nil { | ||
glog.Errorf("Failed to create a file system options=%#v: %v", options, err) | ||
return nil, err | ||
} | ||
fsID = *resp.FileSystem.Id | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reassign logger
.With("fileSystemID", fsID)
@@ -174,15 +185,15 @@ func (fsp *filesystemProvisioner) Provision(options controller.VolumeOptions, ad | |||
}, | |||
}) | |||
if err != nil { | |||
glog.Errorf("Failed to create export: %v", err) | |||
logger.With(zap.Error(err)).Error("Failed to create export.") | |||
return nil, err | |||
} | |||
exportSetID = *resp.Export.Id | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reassign logger
.With("exportSetID", exportSetID)
pkg/provisioner/fss/fss.go
Outdated
return nil, err | ||
} | ||
exportSetID = *resp.Export.Id | ||
} | ||
|
||
if len(target.PrivateIpIds) == 0 { | ||
glog.Errorf("Failed to find server IDs associated with the Mount Target (OCID %s) to provision a persistent volume", target.Id) | ||
return nil, errors.Errorf("failed to find server IDs associated with the Mount Target with OCID %q", target.Id) | ||
logger.With("targetID", *target.Id).Error("Failed to find server IDs associated with the Mount Target to provision a persistent volume") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change the error and log message to something along the lines of "Could not find any Private IPs for Mount Target"?
aae1dc4
to
affa9cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple final changes and needs rebasing but looking good 👍
cmd/main.go
Outdated
|
||
//logger.Infof("logtostderr is set to %b", flag.Lookup("logtostderr").Value.(flag.Getter).Get().(bool)) | ||
|
||
//logger.Sugar().With("version", version, "build", build).Info("oci-volume-provisioner") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should log the version and build.
cmd/main.go
Outdated
|
||
logger := log.Sugar() | ||
|
||
//logger.Infof("logtostderr is set to %b", flag.Lookup("logtostderr").Value.(flag.Getter).Get().(bool)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed.
cmd/main.go
Outdated
"github.com/oracle/oci-volume-provisioner/pkg/provisioner/core" | ||
"github.com/oracle/oci-volume-provisioner/pkg/signals" | ||
"go.uber.org/zap" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import grouping
cmd/main.go
Outdated
kubeconfig := flag.String("kubeconfig", "", "Path to Kubeconfig file with authorization and master location information.") | ||
volumeRoundingEnabled := flag.Bool("rounding-enabled", true, "When enabled volumes will be rounded up if less than 'minVolumeSizeMB'") | ||
minVolumeSize := flag.String("min-volume-size", "50Gi", "The minimum size for a block volume. By default OCI only supports block volumes > 50GB") | ||
master := flag.String("master", "", "The address of the Kubernetes API server (overrides any value in kubeconfig).") | ||
flag.Parse() | ||
flag.Set("logtostderr", "true") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this now (it's glog specific).
pkg/oci/client/client.go
Outdated
"github.com/golang/glog" | ||
"github.com/pkg/errors" | ||
"go.uber.org/zap" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confusingly github.com/oracle/oci-go-sdk
is actually an 3rd partly lib rather than internal and as such should be grouped with zap and errors etc.
pkg/oci/client/client.go
Outdated
@@ -111,24 +114,30 @@ func (p *provisionerClient) Timeout() time.Duration { | |||
func (p *provisionerClient) CompartmentOCID() (compartmentOCID string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (p *provisionerClient) CompartmentOCID() string {
if p.cfg.CompartmentOCID == "" {
if p.metadata == nil {
p.logger.Fatal("Unable to get compartment OCID. Please provide this via config.")
return
}
p.logger.With("compartmentOCID", p.metadata.CompartmentOCID).Infof("'CompartmentID' not given. Using compartment OCID from instance metadata.")
p.cfg.CompartmentOCID = p.metadata.CompartmentOCID
}
return p.cfg.CompartmentOCID
}
pkg/oci/client/client.go
Outdated
} else { | ||
compartmentOCID = p.cfg.CompartmentOCID | ||
} | ||
return | ||
} | ||
|
||
func (p *provisionerClient) TenancyOCID() string { | ||
return p.cfg.Auth.TenancyOCID | ||
func (p *provisionerClient) TenancyOCID() (tenancyOCID string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to name the return type here
pkg/oci/client/client.go
Outdated
blockStorage *core.BlockstorageClient | ||
identity *identity.IdentityClient | ||
fileStorage *filestorage.FileStorageClient | ||
virtualNetwork *core.VirtualNetworkClient | ||
context context.Context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Contexts should never be added as a property on a struct.
c5696fa
to
76e4ba4
Compare
76e4ba4
to
45750ca
Compare
Awaiting fix for system-tests |
45750ca
to
0dbb763
Compare
Migrates logging from to go.uber.org/zap from github.com/golang/glog and adds the following flags: