github.com/containerd/nerdctl@v1.7.7/pkg/rootlessutil/rootlessutil_other.go (about)

     1  //go:build !linux
     2  
     3  /*
     4     Copyright The containerd Authors.
     5  
     6     Licensed under the Apache License, Version 2.0 (the "License");
     7     you may not use this file except in compliance with the License.
     8     You may obtain a copy of the License at
     9  
    10         http://www.apache.org/licenses/LICENSE-2.0
    11  
    12     Unless required by applicable law or agreed to in writing, software
    13     distributed under the License is distributed on an "AS IS" BASIS,
    14     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15     See the License for the specific language governing permissions and
    16     limitations under the License.
    17  */
    18  
    19  // On non-Linux platforms, the rootlessutil package always denies
    20  // rootlessness and errors out, since RootlessKit only works on Linux
    21  // and none of the Windows containerd runtimes can be considered rootless.
    22  // https://github.com/containerd/nerdctl/issues/2115
    23  package rootlessutil
    24  
    25  import (
    26  	"fmt"
    27  
    28  	"github.com/rootless-containers/rootlesskit/pkg/api/client"
    29  )
    30  
    31  // Always returns false on non-Linux platforms.
    32  func IsRootless() bool {
    33  	return false
    34  }
    35  
    36  // Always returns false on non-Linux platforms.
    37  func IsRootlessChild() bool {
    38  	return false
    39  }
    40  
    41  // Always returns false on non-Linux platforms.
    42  func IsRootlessParent() bool {
    43  	return false
    44  }
    45  
    46  // Always errors out on non-Linux platforms.
    47  func XDGRuntimeDir() (string, error) {
    48  	return "", fmt.Errorf("can only query XDG env vars on Linux")
    49  }
    50  
    51  // Always returns -1 on non-Linux platforms.
    52  func ParentEUID() int {
    53  	return -1
    54  }
    55  
    56  // Always errors out on non-Linux platforms.
    57  func NewRootlessKitClient() (client.Client, error) {
    58  	return nil, fmt.Errorf("cannot instantiate RootlessKit client on non-Linux hosts")
    59  }
    60  
    61  // Always errors out on non-Linux platforms.
    62  func ParentMain(hostGatewayIP string) error {
    63  	return fmt.Errorf("cannot use RootlessKit on main entry point on non-Linux hosts")
    64  }
    65  
    66  func RootlessContainredSockAddress() (string, error) {
    67  	return "", fmt.Errorf("cannot inspect RootlessKit state on non-Linux hosts")
    68  }