Skip to content

Commit

Permalink
Refactor NIMCache as it is platform independent (#7)
Browse files Browse the repository at this point in the history
Signed-off-by: Shiva Krishna, Merla <smerla@nvidia.com>
  • Loading branch information
shivamerla authored Aug 1, 2024
1 parent 12e9582 commit 45edafa
Show file tree
Hide file tree
Showing 13 changed files with 1,110 additions and 1,339 deletions.
12 changes: 12 additions & 0 deletions api/v1alpha1/nimcache_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1alpha1

import (
"fmt"

corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -225,6 +227,16 @@ type NIMCache struct {
Status NIMCacheStatus `json:"status,omitempty"`
}

// GetPVCName returns the name to be used for the PVC based on the custom spec
// Prefers pvc.Name if explicitly set by the user in the NIMCache instance
func (n *NIMCache) GetPVCName(pvc PersistentVolumeClaim) string {
pvcName := fmt.Sprintf("%s-pvc", n.GetName())
if pvc.Name != nil {
pvcName = *pvc.Name
}
return pvcName
}

// +kubebuilder:object:root=true

// NIMCacheList contains a list of NIMCache
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/nimservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ type NIMServiceList struct {
Items []NIMService `json:"items"`
}

// GetPVCName returns the name to be used for the PVC based on the custom spec
// Prefers pvc.Name if explicitly set by the user in the NIMService instance
func (n *NIMService) GetPVCName(pvc PersistentVolumeClaim) string {
pvcName := fmt.Sprintf("%s-pvc", n.GetName())
if pvc.Name != nil {
pvcName = *pvc.Name
}
return pvcName
}

// GetStandardSelectorLabels returns the standard selector labels for the NIMService deployment
func (n *NIMService) GetStandardSelectorLabels() map[string]string {
return map[string]string{
Expand Down
24 changes: 24 additions & 0 deletions internal/conditions/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,27 @@ func (u *updater) SetConditionsFailed(ctx context.Context, cr *appsv1alpha1.NIMS
cr.Status.State = NotReady
return u.client.Status().Update(ctx, cr)
}

// UpdateCondition updates the given condition into the conditions list
func UpdateCondition(conditions *[]metav1.Condition, conditionType string, status metav1.ConditionStatus, reason, message string) {
for i := range *conditions {
if (*conditions)[i].Type == conditionType {
// existing condition
(*conditions)[i].Status = status
(*conditions)[i].LastTransitionTime = metav1.Now()
(*conditions)[i].Reason = reason
(*conditions)[i].Message = message
// condition updated
return
}
}
// new condition
*conditions = append(*conditions, metav1.Condition{
Type: conditionType,
Status: status,
LastTransitionTime: metav1.Now(),
Reason: reason,
Message: message,
})
// condition updated
}
Loading

0 comments on commit 45edafa

Please sign in to comment.