-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make podRef to be unique #433
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import ( | |
"k8s.io/client-go/kubernetes/scheme" | ||
typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/client-go/tools/record" | ||
|
||
nadclient "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/clientset/versioned" | ||
|
@@ -38,6 +39,7 @@ const ( | |
cronSchedulerCreationError | ||
fileWatcherError | ||
couldNotCreateConfigWatcherError | ||
initialReconsileFailed | ||
) | ||
|
||
const ( | ||
|
@@ -78,6 +80,16 @@ func main() { | |
} | ||
defer watcher.Close() | ||
|
||
// trigger one immediate reconcile before cron job start | ||
go reconciler.ReconcileIPs(errorChan) | ||
err = <-errorChan | ||
if err == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
|
||
logging.Verbosef("initial reconciler success") | ||
} else { | ||
logging.Verbosef("initial reconciler failure: %s", err) | ||
os.Exit(initialReconsileFailed) | ||
} | ||
|
||
reconcilerConfigWatcher, err := reconciler.NewConfigWatcher( | ||
reconcilerCronConfiguration, | ||
s, | ||
|
@@ -125,9 +137,19 @@ func handleSignals(stopChannel chan struct{}, signals ...os.Signal) { | |
} | ||
|
||
func newPodController(stopChannel chan struct{}) (*controlloop.PodController, error) { | ||
cfg, err := rest.InClusterConfig() | ||
var cfg *rest.Config | ||
var err error | ||
cfg, err = rest.InClusterConfig() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is run inside the cluster, but the
So your code can end up using the in cluster config for one, and the kubeconfig for the other |
||
if err != nil { | ||
return nil, fmt.Errorf("failed to implicitly generate the kubeconfig: %w", err) | ||
logging.Debugf("failed to generate the kubeconfig from service account: %v", err) | ||
kubeConfigFile := os.Getenv("KUBECONFIG") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. both |
||
if kubeConfigFile == "" { | ||
return nil, fmt.Errorf("KUBECONFIG environment variable not set") | ||
} | ||
cfg, err = clientcmd.BuildConfigFromFlags("", kubeConfigFile) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to generate kubeconfig from file %s: %v", kubeConfigFile, err) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for the improved logging on error |
||
} | ||
|
||
k8sClientSet, err := kubernetes.NewForConfig(cfg) | ||
|
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.
nit: initialReconsileFailed -> initialReconcileFailed