Skip to content

Commit

Permalink
improve error message (openyurtio#1792)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzcvxe authored Nov 16, 2023
1 parent 15bd83b commit 754ccf8
Show file tree
Hide file tree
Showing 112 changed files with 531 additions and 532 deletions.
15 changes: 7 additions & 8 deletions cmd/yurt-iot-dock/app/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,21 @@ func Run(opts *options.YurtIoTDockOptions, stopCh <-chan struct{}) {
// perform preflight check
setupLog.Info("[preflight] Running pre-flight checks")
if err := preflightCheck(mgr, opts); err != nil {
setupLog.Error(err, "failed to run pre-flight checks")
setupLog.Error(err, "could not run pre-flight checks")
os.Exit(1)
}

// register the field indexers
setupLog.Info("[preflight] Registering the field indexers")
if err := util.RegisterFieldIndexers(mgr.GetFieldIndexer()); err != nil {
setupLog.Error(err, "failed to register field indexers")
setupLog.Error(err, "could not register field indexers")
os.Exit(1)
}

// get nodepool where yurt-iot-dock run
if opts.Nodepool == "" {
opts.Nodepool, err = util.GetNodePool(mgr.GetConfig())
if err != nil {
setupLog.Error(err, "failed to get the nodepool where yurt-iot-dock run")
setupLog.Error(err, "could not get the nodepool where yurt-iot-dock run")
os.Exit(1)
}
}
Expand Down Expand Up @@ -188,27 +187,27 @@ func Run(opts *options.YurtIoTDockOptions, stopCh <-chan struct{}) {

setupLog.Info("[run controllers] Starting manager, acting on " + fmt.Sprintf("[NodePool: %s, Namespace: %s]", opts.Nodepool, opts.Namespace))
if err := mgr.Start(SetupSignalHandler(mgr.GetClient(), opts)); err != nil {
setupLog.Error(err, "failed to running manager")
setupLog.Error(err, "could not running manager")
os.Exit(1)
}
}

func deleteCRsOnControllerShutdown(ctx context.Context, cli client.Client, opts *options.YurtIoTDockOptions) error {
setupLog.Info("[deleteCRsOnControllerShutdown] start delete device crd")
if err := controllers.DeleteDevicesOnControllerShutdown(ctx, cli, opts); err != nil {
setupLog.Error(err, "failed to shutdown device cr")
setupLog.Error(err, "could not shutdown device cr")
return err
}

setupLog.Info("[deleteCRsOnControllerShutdown] start delete deviceprofile crd")
if err := controllers.DeleteDeviceProfilesOnControllerShutdown(ctx, cli, opts); err != nil {
setupLog.Error(err, "failed to shutdown deviceprofile cr")
setupLog.Error(err, "could not shutdown deviceprofile cr")
return err
}

setupLog.Info("[deleteCRsOnControllerShutdown] start delete deviceservice crd")
if err := controllers.DeleteDeviceServicesOnControllerShutdown(ctx, cli, opts); err != nil {
setupLog.Error(err, "failed to shutdown deviceservice cr")
setupLog.Error(err, "could not shutdown deviceservice cr")
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/yurt-node-servant/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func newCmdConfigControlPlane() *cobra.Command {
return err
}
if err := runner.Do(); err != nil {
return fmt.Errorf("failed to config control-plane, %v", err)
return fmt.Errorf("could not config control-plane, %v", err)
}

klog.Info("node-servant config control-plane success")
Expand Down
2 changes: 1 addition & 1 deletion cmd/yurt-node-servant/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewConvertCmd() *cobra.Command {

converter := nodeconverter.NewConverterWithOptions(o)
if err := converter.Do(); err != nil {
klog.Fatalf("fail to convert the kubernetes node to a yurt node: %s", err)
klog.Fatalf("could not convert the kubernetes node to a yurt node: %s", err)
}
klog.Info("convert success")
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/yurt-node-servant/revert/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func NewRevertCmd() *cobra.Command {
Short: "",
Run: func(cmd *cobra.Command, args []string) {
if err := o.Complete(cmd.Flags()); err != nil {
klog.Fatalf("fail to complete the revert option: %s", err)
klog.Fatalf("could not complete the revert option: %s", err)
}

r := revert.NewReverterWithOptions(o)
if err := r.Do(); err != nil {
klog.Fatalf("fail to revert the yurt node to a kubernetes node: %s", err)
klog.Fatalf("could not revert the yurt node to a kubernetes node: %s", err)
}
klog.Info("revert success")
},
Expand Down
6 changes: 3 additions & 3 deletions cmd/yurt-node-servant/static-pod-upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ func NewUpgradeCmd() *cobra.Command {
})

if err := o.Validate(); err != nil {
klog.Fatalf("Fail to validate static pod upgrade args, %v", err)
klog.Fatalf("could not validate static pod upgrade args, %v", err)
}

ctrl, err := upgrade.NewWithOptions(o)
if err != nil {
klog.Fatalf("Fail to create static-pod-upgrade controller, %v", err)
klog.Fatalf("could not create static-pod-upgrade controller, %v", err)
}

if err = ctrl.Upgrade(); err != nil {
klog.Fatalf("Fail to upgrade static pod, %v", err)
klog.Fatalf("could not upgrade static pod, %v", err)
}

klog.Info("Static pod upgrade Success")
Expand Down
2 changes: 1 addition & 1 deletion cmd/yurt-tunnel-server/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (o *ServerOptions) Config() (*config.Config, error) {
cfg.ListenMetaAddr = net.JoinHostPort(o.InsecureBindAddr, o.MetaPort)
cfg.RootCert, err = certmanager.GenRootCertPool(o.KubeConfig, constants.YurttunnelCAFile)
if err != nil {
return nil, fmt.Errorf("fail to generate the rootCertPool: %w", err)
return nil, fmt.Errorf("could not generate the rootCertPool: %w", err)
}

// function 'kubeutil.CreateClientSet' will try to create the clientset
Expand Down
4 changes: 2 additions & 2 deletions cmd/yurthub/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func Complete(options *options.YurtHubOptions) (*YurtHubConfiguration, error) {
serializerManager := serializer.NewSerializerManager()
restMapperManager, err := meta.NewRESTMapperManager(options.DiskCachePath)
if err != nil {
klog.Errorf("failed to create restMapperManager at path %s, %v", options.DiskCachePath, err)
klog.Errorf("could not create restMapperManager at path %s, %v", options.DiskCachePath, err)
return nil, err
}

Expand Down Expand Up @@ -214,7 +214,7 @@ func parseRemoteServers(serverAddr string) ([]*url.URL, error) {
for _, server := range servers {
u, err := url.Parse(server)
if err != nil {
klog.Errorf("failed to parse server address %q, %v", server, err)
klog.Errorf("could not parse server address %q, %v", server, err)
return us, err
}
if u.Scheme == "" {
Expand Down
22 changes: 11 additions & 11 deletions cmd/yurthub/app/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func Run(ctx context.Context, cfg *config.YurtHubConfiguration) error {
klog.Infof("%d. prepare cloud kube clients", trace)
cloudClients, err := createClients(cfg.HeartbeatTimeoutSeconds, cfg.RemoteServers, transportManager)
if err != nil {
return fmt.Errorf("failed to create cloud clients, %w", err)
return fmt.Errorf("could not create cloud clients, %w", err)
}
trace++

Expand Down Expand Up @@ -249,7 +249,7 @@ func coordinatorRun(ctx context.Context,
coorCertManager, err := coordinatorcertmgr.NewCertManager(cfg.CoordinatorPKIDir, cfg.YurtHubNamespace, cfg.ProxiedClient, cfg.SharedFactory)
close(coordinatorInformerRegistryChan) // notify the coordinator secret informer registry event
if err != nil {
klog.Errorf("coordinator failed to create coordinator cert manager, %v", err)
klog.Errorf("coordinator could not create coordinator cert manager, %v", err)
return
}
klog.Info("coordinator new certManager success")
Expand All @@ -274,30 +274,30 @@ func coordinatorRun(ctx context.Context,
if apiServerIP == nil {
apiServerService, err := serviceList.Services(util.YurtHubNamespace).Get(cfg.CoordinatorServerURL.Hostname())
if err != nil {
klog.Errorf("coordinator failed to get apiServer service, %v", err)
klog.Errorf("coordinator could not get apiServer service, %v", err)
return
}
// rewrite coordinator service info for cfg
coordinatorServerURL, err :=
url.Parse(fmt.Sprintf("https://%s:%s", apiServerService.Spec.ClusterIP, cfg.CoordinatorServerURL.Port()))
if err != nil {
klog.Errorf("coordinator failed to parse apiServer service, %v", err)
klog.Errorf("coordinator could not parse apiServer service, %v", err)
return
}
cfg.CoordinatorServerURL = coordinatorServerURL
}
if etcdIP == nil {
etcdService, err := serviceList.Services(util.YurtHubNamespace).Get(etcdUrl.Hostname())
if err != nil {
klog.Errorf("coordinator failed to get etcd service, %v", err)
klog.Errorf("coordinator could not get etcd service, %v", err)
return
}
cfg.CoordinatorStorageAddr = fmt.Sprintf("https://%s:%s", etcdService.Spec.ClusterIP, etcdUrl.Port())
}

coorTransportMgr, err := yurtCoordinatorTransportMgrGetter(coorCertManager, ctx.Done())
if err != nil {
klog.Errorf("coordinator failed to create coordinator transport manager, %v", err)
klog.Errorf("coordinator could not create coordinator transport manager, %v", err)
return
}

Expand All @@ -307,27 +307,27 @@ func coordinatorRun(ctx context.Context,
Timeout: time.Duration(cfg.HeartbeatTimeoutSeconds) * time.Second,
})
if err != nil {
klog.Errorf("coordinator failed to get coordinator client for yurt coordinator, %v", err)
klog.Errorf("coordinator could not get coordinator client for yurt coordinator, %v", err)
return
}

coorHealthChecker, err := healthchecker.NewCoordinatorHealthChecker(cfg, coordinatorClient, cloudHealthChecker, ctx.Done())
if err != nil {
klog.Errorf("coordinator failed to create coordinator health checker, %v", err)
klog.Errorf("coordinator could not create coordinator health checker, %v", err)
return
}

var elector *yurtcoordinator.HubElector
elector, err = yurtcoordinator.NewHubElector(cfg, coordinatorClient, coorHealthChecker, cloudHealthChecker, ctx.Done())
if err != nil {
klog.Errorf("coordinator failed to create hub elector, %v", err)
klog.Errorf("coordinator could not create hub elector, %v", err)
return
}
go elector.Run(ctx.Done())

coor, err := yurtcoordinator.NewCoordinator(ctx, cfg, cloudHealthChecker, restConfigMgr, coorCertManager, coorTransportMgr, elector)
if err != nil {
klog.Errorf("coordinator failed to create coordinator, %v", err)
klog.Errorf("coordinator could not create coordinator, %v", err)
return
}
go coor.Run()
Expand Down Expand Up @@ -366,7 +366,7 @@ func yurtCoordinatorTransportMgrGetter(coordinatorCertMgr *coordinatorcertmgr.Ce

coordinatorTransportMgr, err := transport.NewTransportManager(coordinatorCertMgr, stopCh)
if err != nil {
return nil, fmt.Errorf("failed to create transport manager for yurt coordinator, %v", err)
return nil, fmt.Errorf("could not create transport manager for yurt coordinator, %v", err)
}
return coordinatorTransportMgr, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/node-servant/components/yurthub.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (op *yurtHubOperator) Install() error {
}
content, err := os.ReadFile(configMapDataPath)
if err != nil {
return fmt.Errorf("failed to read source file %s: %w", configMapDataPath, err)
return fmt.Errorf("could not read source file %s: %w", configMapDataPath, err)
}
klog.Infof("yurt-hub.yaml apiServerAddr: %+v", op.apiServerAddr)
yssYurtHub, err := tmplutil.SubsituteTemplate(string(content), map[string]string{
Expand Down Expand Up @@ -224,7 +224,7 @@ func pingClusterHealthz(client *http.Client, addr string) (bool, error) {
b, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
return false, fmt.Errorf("failed to read response of cluster healthz, %w", err)
return false, fmt.Errorf("could not read response of cluster healthz, %w", err)
}

if resp.StatusCode != http.StatusOK {
Expand Down
2 changes: 1 addition & 1 deletion pkg/node-servant/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func RenderNodeServantJob(action string, renderCtx map[string]string, nodeName s
}
srvJob, ok := srvJobObj.(*batchv1.Job)
if !ok {
return nil, fmt.Errorf("fail to assert node-servant job")
return nil, fmt.Errorf("could not assert node-servant job")
}

return srvJob, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/node-servant/static-pod-upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ func (ctrl *Controller) AutoUpgrade() error {
ok, err := ctrl.verify()
if err != nil {
if err := ctrl.rollbackManifest(); err != nil {
klog.Errorf("Fail to rollback manifest when upgrade failed, %v", err)
klog.Errorf("could not rollback manifest when upgrade failed, %v", err)
}
return err
}
if !ok {
if err := ctrl.rollbackManifest(); err != nil {
klog.Errorf("Fail to rollback manifest when upgrade failed, %v", err)
klog.Errorf("could not rollback manifest when upgrade failed, %v", err)
}
return fmt.Errorf("the latest static pod is not running")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/node-servant/static-pod-upgrade/util/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func GetPodFromYurtHub(namespace, name string) (*v1.Pod, error) {
}
}

return nil, fmt.Errorf("fail to find pod %s/%s", namespace, name)
return nil, fmt.Errorf("could not find pod %s/%s", namespace, name)
}

func GetPodsFromYurtHub(url string) (*v1.PodList, error) {
Expand Down Expand Up @@ -75,7 +75,7 @@ func getPodsDataFromYurtHub(url string) ([]byte, error) {
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("fail to access yurthub pods API, returned status: %v", resp.Status)
return nil, fmt.Errorf("could not access yurthub pods API, returned status: %v", resp.Status)
}

data, err := ioutil.ReadAll(resp.Body)
Expand All @@ -92,7 +92,7 @@ func decodePods(data []byte) (*v1.PodList, error) {

podList := new(v1.PodList)
if _, _, err := codec.Decode(data, nil, podList); err != nil {
return nil, fmt.Errorf("failed to decode pod list: %s", err)
return nil, fmt.Errorf("could not decode pod list: %s", err)
}
return podList, nil
}
6 changes: 3 additions & 3 deletions pkg/util/certmanager/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (f *factory) New(cfg *CertManagerConfig) (certificate.Manager, error) {
if util.IsNil(f.fileStore) {
f.fileStore, err = store.NewFileStoreWrapper(cfg.ComponentName, cfg.CertDir, cfg.CertDir, "", "")
if err != nil {
return nil, fmt.Errorf("failed to initialize the server certificate store: %w", err)
return nil, fmt.Errorf("could not initialize the server certificate store: %w", err)
}
}

Expand All @@ -117,7 +117,7 @@ func (f *factory) New(cfg *CertManagerConfig) (certificate.Manager, error) {
ips = newIPs
}
if err != nil {
klog.Errorf("failed to get ips for %s when preparing cr template, %v", cfg.ComponentName, err)
klog.Errorf("could not get ips for %s when preparing cr template, %v", cfg.ComponentName, err)
return nil
}
}
Expand All @@ -128,7 +128,7 @@ func (f *factory) New(cfg *CertManagerConfig) (certificate.Manager, error) {
dnsNames = newDNSNames
}
if err != nil {
klog.Errorf("failed to get dns names for %s when preparing cr template, %v", cfg.ComponentName, err)
klog.Errorf("could not get dns names for %s when preparing cr template, %v", cfg.ComponentName, err)
return nil
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/certmanager/pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func GenRootCertPool(kubeConfig, caFile string) (*x509.CertPool, error) {
// load the root ca from the given kubeconfig file
config, err := clientcmd.LoadFromFile(kubeConfig)
if err != nil || config == nil {
return nil, fmt.Errorf("failed to load the kubeconfig file(%s), %w",
return nil, fmt.Errorf("could not load the kubeconfig file(%s), %w",
kubeConfig, err)
}

Expand Down Expand Up @@ -173,7 +173,7 @@ func GenCertPoolUseCA(caFile string) (*x509.CertPool, error) {
if os.IsNotExist(err) {
return nil, fmt.Errorf("CA file(%s) doesn't exist", caFile)
}
return nil, fmt.Errorf("fail to stat the CA file(%s): %w", caFile, err)
return nil, fmt.Errorf("could not stat the CA file(%s): %w", caFile, err)
}

caData, err := os.ReadFile(caFile)
Expand Down
10 changes: 5 additions & 5 deletions pkg/yurtadm/cmd/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func newJoinData(args []string, opt *joinOptions) (*joinData, error) {
// Either use specified nodename or get hostname from OS envs
name, err := edgenode.GetHostname(opt.nodeName)
if err != nil {
klog.Errorf("failed to get node name, %v", err)
klog.Errorf("could not get node name, %v", err)
return nil, err
}

Expand Down Expand Up @@ -327,22 +327,22 @@ func newJoinData(args []string, opt *joinOptions) (*joinData, error) {
// get tls bootstrap config
cfg, err := yurtadmutil.RetrieveBootstrapConfig(data)
if err != nil {
klog.Errorf("failed to retrieve bootstrap config, %v", err)
klog.Errorf("could not retrieve bootstrap config, %v", err)
return nil, err
}
data.tlsBootstrapCfg = cfg

// get kubernetes version
client, err := kubeconfigutil.ToClientSet(cfg)
if err != nil {
klog.Errorf("failed to create bootstrap client, %v", err)
klog.Errorf("could not create bootstrap client, %v", err)
return nil, err
}
data.clientSet = client

k8sVersion, err := yurtadmutil.GetKubernetesVersionFromCluster(client)
if err != nil {
klog.Errorf("failed to get kubernetes version, %v", err)
klog.Errorf("could not get kubernetes version, %v", err)
return nil, err
}
data.kubernetesVersion = k8sVersion
Expand Down Expand Up @@ -400,7 +400,7 @@ func newJoinData(args []string, opt *joinOptions) (*joinData, error) {

yurthubManifest, yurthubTemplate, err := yurtadmutil.GetStaticPodTemplateFromConfigMap(client, opt.namespace, util.WithConfigMapPrefix(yurthubYurtStaticSetName))
if err != nil {
klog.Errorf("hard-code yurthub manifest will be used, because failed to get yurthub template from kube-apiserver, %v", err)
klog.Errorf("hard-code yurthub manifest will be used, because could not get yurthub template from kube-apiserver, %v", err)
yurthubManifest = yurtconstants.YurthubStaticPodManifest
yurthubTemplate = yurtconstants.YurthubTemplate

Expand Down
2 changes: 1 addition & 1 deletion pkg/yurtadm/cmd/renew/certificate/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func parseRemoteServers(serverAddr string) ([]*url.URL, error) {
for _, server := range servers {
u, err := url.Parse(server)
if err != nil {
klog.Errorf("failed to parse server address %s, %v", servers, err)
klog.Errorf("could not parse server address %s, %v", servers, err)
return us, err
}
if u.Scheme == "" {
Expand Down
Loading

0 comments on commit 754ccf8

Please sign in to comment.