-
Notifications
You must be signed in to change notification settings - Fork 260
feat: add image and manifest for windows npm #1098
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
Changes from all commits
78f5698
50f0dc5
9e5aa9f
49e971b
b0717d0
7c55fde
3a5af56
54341df
e940bae
99986d5
9672fc5
eb6f90d
d1ba310
a5f9f67
8a9b306
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 |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import ( | |
| "k8s.io/client-go/informers" | ||
| "k8s.io/client-go/kubernetes" | ||
| "k8s.io/client-go/rest" | ||
| "k8s.io/client-go/tools/clientcmd" | ||
| "k8s.io/klog" | ||
| "k8s.io/utils/exec" | ||
| ) | ||
|
|
@@ -40,8 +41,9 @@ func newStartNPMCmd() *cobra.Command { | |
| viper.SetConfigFile(cfgFile) | ||
|
|
||
| // If a config file is found, read it in. | ||
| // NOTE: there is no config merging with default, if config is loaded, options must be set | ||
| if err := viper.ReadInConfig(); err == nil { | ||
matmerr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| klog.Info("Using config file: ", viper.ConfigFileUsed()) | ||
| klog.Infof("Using config file: %+v", viper.ConfigFileUsed()) | ||
| } else { | ||
| klog.Infof("Failed to load config from env %s: %v", npmconfig.ConfigEnvPath, err) | ||
| b, _ := json.Marshal(npmconfig.DefaultConfig) | ||
|
|
@@ -58,36 +60,50 @@ func newStartNPMCmd() *cobra.Command { | |
| config := &npmconfig.Config{} | ||
| err := viper.Unmarshal(config) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to load config with error %w", err) | ||
| return fmt.Errorf("failed to load config with error: %w", err) | ||
| } | ||
|
|
||
| return start(*config) | ||
| flags := npmconfig.Flags{ | ||
| KubeConfigPath: viper.GetString(flagKubeConfigPath), | ||
| } | ||
|
|
||
| return start(*config, flags) | ||
| }, | ||
| } | ||
|
|
||
| startNPMCmd.Flags().String(flagKubeConfigPath, flagDefaults[flagKubeConfigPath], "path to kubeconfig") | ||
|
|
||
| return startNPMCmd | ||
| } | ||
|
|
||
| func start(config npmconfig.Config) error { | ||
| func start(config npmconfig.Config, flags npmconfig.Flags) error { | ||
| klog.Infof("loaded config: %+v", config) | ||
| klog.Infof("Start NPM version: %s", version) | ||
|
|
||
| var err error | ||
| defer func() { | ||
|
Contributor
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. Is there a reason to remove recover ?
Member
Author
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 we have a crash we want to crash hard and bubble that up to orchestrator |
||
| if r := recover(); r != nil { | ||
| klog.Infof("recovered from error: %v", err) | ||
| } | ||
| }() | ||
|
|
||
| if err = initLogging(); err != nil { | ||
| err = initLogging() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| klog.Infof("initializing metrics") | ||
| metrics.InitializeAll() | ||
|
|
||
| // Creates the in-cluster config | ||
| k8sConfig, err := rest.InClusterConfig() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to load in cluster config: %w", err) | ||
| // Create the kubernetes client | ||
| var k8sConfig *rest.Config | ||
| if flags.KubeConfigPath == "" { | ||
| klog.Infof("loading in cluster kubeconfig") | ||
| k8sConfig, err = rest.InClusterConfig() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to load in cluster config: %w", err) | ||
| } | ||
| } else { | ||
| klog.Infof("loading kubeconfig from flag: %s", flags.KubeConfigPath) | ||
| k8sConfig, err = clientcmd.BuildConfigFromFlags("", flags.KubeConfigPath) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to load kubeconfig [%s] with err config: %w", flags.KubeConfigPath, err) | ||
| } | ||
| } | ||
|
|
||
| // Creates the clientset | ||
|
|
@@ -101,7 +117,7 @@ func start(config npmconfig.Config) error { | |
| minResyncPeriod := time.Duration(config.ResyncPeriodInMinutes) * time.Minute | ||
|
|
||
| // Adding some randomness so all NPM pods will not request for info at once. | ||
| factor := rand.Float64() + 1 | ||
| factor := rand.Float64() + 1 //nolint | ||
| resyncPeriod := time.Duration(float64(minResyncPeriod.Nanoseconds()) * factor) | ||
| klog.Infof("Resync period for NPM pod is set to %d.", int(resyncPeriod/time.Minute)) | ||
| factory := informers.NewSharedInformerFactory(clientset, resyncPeriod) | ||
|
|
@@ -125,8 +141,8 @@ func start(config npmconfig.Config) error { | |
| go restserver.NPMRestServerListenAndServe(config, npMgr) | ||
|
|
||
| if err = npMgr.Start(config, wait.NeverStop); err != nil { | ||
| metrics.SendErrorLogAndMetric(util.NpmID, "Failed to start NPM due to %s", err) | ||
| panic(err.Error) | ||
| metrics.SendErrorLogAndMetric(util.NpmID, "Failed to start NPM due to %+v", err) | ||
| return fmt.Errorf("failed to start with err: %w", err) | ||
| } | ||
|
|
||
| select {} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,3 +36,7 @@ type Toggles struct { | |
| EnableV2NPM bool | ||
| PlaceAzureChainFirst bool | ||
| } | ||
|
|
||
| type Flags struct { | ||
| KubeConfigPath string `json:"KubeConfigPath"` | ||
|
Contributor
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. Is there any value in adding all our configmap params under flags ?
Member
Author
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. it makes the signature for start cleaner, passing in config struct and flags struct, when we add more flags in the future
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: azure-npm | ||
| namespace: kube-system | ||
| labels: | ||
| addonmanager.kubernetes.io/mode: EnsureExists | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: azure-npm | ||
| namespace: kube-system | ||
| labels: | ||
| addonmanager.kubernetes.io/mode: EnsureExists | ||
| rules: | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - pods | ||
| - nodes | ||
| - namespaces | ||
| verbs: | ||
| - get | ||
| - list | ||
| - watch | ||
| - apiGroups: | ||
| - networking.k8s.io | ||
| resources: | ||
| - networkpolicies | ||
| verbs: | ||
| - get | ||
| - list | ||
| - watch | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: azure-npm-binding | ||
| namespace: kube-system | ||
| labels: | ||
| addonmanager.kubernetes.io/mode: EnsureExists | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: azure-npm | ||
| namespace: kube-system | ||
| roleRef: | ||
| kind: ClusterRole | ||
| name: azure-npm | ||
| apiGroup: rbac.authorization.k8s.io | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: DaemonSet | ||
| metadata: | ||
| name: azure-npm | ||
| namespace: kube-system | ||
| labels: | ||
| app: azure-npm | ||
| addonmanager.kubernetes.io/mode: EnsureExists | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| k8s-app: azure-npm | ||
| template: | ||
| metadata: | ||
| labels: | ||
| k8s-app: azure-npm | ||
| annotations: | ||
| azure.npm/scrapeable: '' | ||
| spec: | ||
| priorityClassName: system-node-critical | ||
| tolerations: | ||
| - operator: "Exists" | ||
| effect: NoExecute | ||
| - operator: "Exists" | ||
| effect: NoSchedule | ||
| - key: CriticalAddonsOnly | ||
| operator: Exists | ||
| securityContext: | ||
| windowsOptions: | ||
| hostProcess: true | ||
| runAsUserName: "NT AUTHORITY\\SYSTEM" | ||
| hostNetwork: true | ||
| containers: | ||
| - name: azure-npm | ||
| image: acnpublic.azurecr.io/azure-npm:v26-windows-amd64 | ||
| command: ["powershell.exe"] | ||
| args: ['.\setkubeconfigpath.ps1', ';', 'powershell.exe', '.\npm.exe', "start", '--kubeconfig=.\kubeconfig'] | ||
| resources: | ||
| limits: | ||
| cpu: 250m | ||
| memory: 300Mi | ||
| requests: | ||
| cpu: 250m | ||
| env: | ||
| - name: HOSTNAME | ||
| valueFrom: | ||
| fieldRef: | ||
| apiVersion: v1 | ||
| fieldPath: spec.nodeName | ||
| - name: NPM_CONFIG | ||
| value: .\\etc\\azure-npm\\azure-npm.json | ||
| volumeMounts: | ||
| - name: azure-npm-config | ||
| mountPath: .\\etc\\azure-npm | ||
| nodeSelector: | ||
| kubernetes.io/os: windows | ||
| volumes: | ||
| - name: azure-npm-config | ||
| configMap: | ||
| name: azure-npm-config | ||
| serviceAccountName: azure-npm | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: npm-metrics-cluster-service | ||
| namespace: kube-system | ||
| labels: | ||
| app: npm-metrics | ||
| spec: | ||
| selector: | ||
| k8s-app: azure-npm | ||
| ports: | ||
| - port: 9000 | ||
| targetPort: 10091 | ||
| --- | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: azure-npm-config | ||
| namespace: kube-system | ||
| data: | ||
| azure-npm.json: | | ||
| { | ||
| "ResyncPeriodInMinutes": 15, | ||
| "ListeningPort": 10091, | ||
| "ListeningAddress": "0.0.0.0", | ||
| "Toggles": { | ||
| "EnablePrometheusMetrics": true, | ||
| "EnablePprof": true, | ||
| "EnableHTTPDebugAPI": true, | ||
| "EnableV2Controllers": true | ||
| } | ||
| } | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| apiVersion: v1 | ||
| kind: Config | ||
| clusters: | ||
| - name: kubernetes | ||
| cluster: | ||
| certificate-authority-data: <ca> | ||
| <server> | ||
| contexts: | ||
| - name: azure-npm-windows@kubernetes | ||
| context: | ||
| cluster: kubernetes | ||
| namespace: kube-system | ||
| user: azure-npm-windows | ||
| current-context: azure-npm-windows@kubernetes | ||
| users: | ||
| - name: azure-npm-windows | ||
| user: | ||
| token: <token> |
Uh oh!
There was an error while loading. Please reload this page.
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 > remove the space,