Skip to content

Commit

Permalink
validate instanceView state and provingingState
Browse files Browse the repository at this point in the history
Signed-off-by: Heba Elayoty <hebaelayoty@gmail.com>
  • Loading branch information
helayoty committed Jan 24, 2023
1 parent ef04817 commit 9a162f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/provider/containergroup_to_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,23 @@ func (p *ACIProvider) getPodStatusFromContainerGroup(ctx context.Context, cg *az

// cg is validated
allReady := true
var firstContainerStartTime, lastUpdateTime *time.Time
var firstContainerStartTime, lastUpdateTime time.Time

containerStatuses := make([]v1.ContainerStatus, 0, len(cg.Properties.Containers))
containersList := cg.Properties.Containers

if len(containersList) == 0 {
firstContainerStartTime = time.Time{}
lastUpdateTime = time.Time{}
}
for i := range containersList {
err := validation.ValidateContainer(ctx, containersList[i])
logger.Debugf("container %s has missing fields. retrying the validation...", *containersList[i].Name)
if err != nil {
return nil, err
}

firstContainerStartTime = containersList[i].Properties.InstanceView.CurrentState.StartTime
firstContainerStartTime = *containersList[i].Properties.InstanceView.CurrentState.StartTime
lastUpdateTime = firstContainerStartTime

containerStatus := v1.ContainerStatus{
Expand All @@ -74,8 +78,8 @@ func (p *ACIProvider) getPodStatusFromContainerGroup(ctx context.Context, cg *az
}

containerStartTime := containersList[i].Properties.InstanceView.CurrentState.StartTime
if containerStartTime.After(*lastUpdateTime) {
lastUpdateTime = containerStartTime
if containerStartTime.After(lastUpdateTime) {
lastUpdateTime = *containerStartTime
}

// Add to containerStatuses
Expand All @@ -94,12 +98,12 @@ func (p *ACIProvider) getPodStatusFromContainerGroup(ctx context.Context, cg *az
}
return &v1.PodStatus{
Phase: getPodPhaseFromACIState(*aciState),
Conditions: getPodConditionsFromACIState(*aciState, creationTime, *lastUpdateTime, allReady),
Conditions: getPodConditionsFromACIState(*aciState, creationTime, lastUpdateTime, allReady),
Message: "",
Reason: "",
HostIP: p.internalIP,
PodIP: podIp,
StartTime: &metav1.Time{Time: *firstContainerStartTime},
StartTime: &metav1.Time{Time: firstContainerStartTime},
ContainerStatuses: containerStatuses,
}, nil
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/validation/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ func ValidateContainerGroup(ctx context.Context, cg *azaciv2.ContainerGroup) err
if cg.Tags == nil {
return errors.Errorf("tags list cannot be nil for container group %s", *cg.Name)
}
if cg.Properties.InstanceView == nil {
return errors.Errorf("InstanceView cannot be nil for container group %s", *cg.Name)
}
if cg.Properties.InstanceView.State == nil {
return errors.Errorf("InstanceView state cannot be nil for container group %s", *cg.Name)
}
if cg.Properties.OSType != nil &&
*cg.Properties.OSType != azaciv2.OperatingSystemTypesWindows {
if cg.Properties.IPAddress == nil {
return errors.Errorf("IPAddress cannot be nil for container group %s", *cg.Name)
} else {
if cg.Properties.ProvisioningState == nil {
return errors.Errorf("ProvisioningState cannot be nil for container group %s", *cg.Name)
}
aciState := *cg.Properties.ProvisioningState
if cg.Properties.IPAddress.IP == nil {
if aciState == "Running" {
Expand Down

0 comments on commit 9a162f4

Please sign in to comment.