Skip to content

Commit

Permalink
Add leap second configmap
Browse files Browse the repository at this point in the history
This commit adds an empty leap-second configmap
that will be populated by linuxptp-daemon on every node.
It will provide leap-seconds.list file to ts2phc.

Signed-off-by: Vitaly Grinberg <v.g@redhat.com>
  • Loading branch information
Vitaly Grinberg authored and josephdrichard committed Jun 20, 2024
1 parent 15e7713 commit 401ddd8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bindata/linuxptp/ptp-daemon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,20 @@ spec:
fieldPath: metadata.name
- name: PLUGINS
value: "{{ .EnabledPlugins }}"

volumeMounts:
- name: config-volume
mountPath: /etc/linuxptp
- name: leap-volume
mountPath: /etc/leap
- name: socket-dir
mountPath: /var/run
volumes:
- name: config-volume
configMap:
name: ptp-configmap
- name: leap-volume
configMap:
name: leap-configmap
- name: linuxptp-certs
secret:
secretName: linuxptp-daemon-secret
Expand Down
33 changes: 33 additions & 0 deletions controllers/ptpoperatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ func (r *PtpOperatorConfigReconciler) Reconcile(ctx context.Context, req ctrl.Re
return reconcile.Result{}, err
}

if err = r.createLeapConfigMap(ctx, defaultCfg); err != nil {
glog.Errorf("failed to create leap config map: %v", err)
return reconcile.Result{}, err
}

if err = r.syncLinuxptpDaemon(ctx, defaultCfg, nodeList); err != nil {
glog.Errorf("failed to sync linux ptp daemon: %v", err)
if err.Error() == AmqReadyStateError {
Expand All @@ -140,6 +145,34 @@ func (r *PtpOperatorConfigReconciler) Reconcile(ctx context.Context, req ctrl.Re
return reconcile.Result{RequeueAfter: ResyncPeriod}, nil
}

// createLeapConfigMap creates an empty leap second config map
func (r *PtpOperatorConfigReconciler) createLeapConfigMap(ctx context.Context, defaultCfg *ptpv1.PtpOperatorConfig) error {
var err error

cm := &corev1.ConfigMap{}
err = r.Get(ctx, types.NamespacedName{
Namespace: names.Namespace, Name: names.DefaultLeapConfigMapName}, cm)
if err != nil {
if errors.IsNotFound(err) {
cm.Name = names.DefaultLeapConfigMapName
cm.Namespace = names.Namespace
cm.Data = make(map[string]string)

if err = controllerutil.SetControllerReference(defaultCfg, cm, r.Scheme); err != nil {
return fmt.Errorf("failed to set owner reference: %v", err)
}
err = r.Create(ctx, cm)
if err != nil {
return fmt.Errorf("failed to create leap config map: %v", err)
}
glog.Infof("leap config map created successfully")
} else {
return fmt.Errorf("failed to create leap config map: %v", err)
}
}
return nil
}

// createPTPConfigMap creates PTP config map
func (r *PtpOperatorConfigReconciler) createPTPConfigMap(ctx context.Context, defaultCfg *ptpv1.PtpOperatorConfig) error {
var err error
Expand Down
4 changes: 4 additions & 0 deletions pkg/names/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const Namespace = "ptp"
// by ptp-operator.
const DefaultPTPConfigMapName = "ptp-configmap"

// DefaultLeapConfigMapName is the default leap config map that created
// by ptp-operator.
const DefaultLeapConfigMapName = "leap-configmap"

// DefaultOperatorConfigName is the default operator config that
// created by ptp-operator. It's set to the owner of resources of
// linuxptp daemonset, ptp-configmap and nodePtpDevice.
Expand Down

0 comments on commit 401ddd8

Please sign in to comment.